Subject Re: [IBO] "Statement has not been prepared"
Author Helen Borrie
At 11:58 AM 23-09-02 +0000, you wrote:
>Using BCB v5, FB v1.0, IBO v4.2h. Using Non IBO visual controls
>
>I'm hoping this is a simple one.
>
>
>When the user edits the text I locate the row in the query and
>replace the text. OK, so far. However, if the user doesn't make any
>actual changes to the text, I still update the row (see 'Editing a
>row' below). In this case, when the form closes and I Post and then
>commit any changes I get a messagebox pop up saying "Statement has
>not been prepared".
>
>The statement has been prepared because the qry has remained open
>throughout the life time of the form, and it works fine if the user
>actually changes some text.
>
>What's causing this error if I try to post and commit a row that has
>not actually changed? My code is listed below.

Try this instead (excuse the Pascalese):

FormClose:

if qry->NeedToPost
{
qry->Post();
qry->IB_Transaction->Commit();
}
qry->Close();
qry->Unprepare();

Reason: IBO constructs its own UPDATE statement which it prepares if it
needs to (i.e. it has modified data). So it's this statement that is not
prepared if the data are not modified.

If this is a form that you create for the purpose of editing a single
record, then why not provide a selector for the task id BEFORE the form is
created and pass the selected id to a TIB_Cursor that returns just that
record from a parameterised statement?

Helen