Board index » delphi » Error with TQuery and ExecSQL then Open

Error with TQuery and ExecSQL then Open

Hi:

When I try to OPEN a query after an ExecSQL INSERT I get the following
error:

"Error creating cursor handle"

Here's the code:

with qryEvents do begin
    Close;
    SQL.Clear;
    SQL.Add('INSERT INTO EVENTS (EventTypeID) VALUES (11)');
    ExecSQL;

<<OK up to now, but then>>

    Open;    <<Causes the error>>

end; //with

It should be simple. What's wrong? I'm using Delphi 2.0 Desktop and
BDE 3.0 on Win95.

Any suggestions would be appreciated.

Blair Kingsland
bla...@tigron.com

 

Re:Error with TQuery and ExecSQL then Open


Quote
> When I try to OPEN a query after an ExecSQL INSERT I get the following
> error:

> "Error creating cursor handle"

> Here's the code:

> with qryEvents do begin
>     Close;
>     SQL.Clear;
>     SQL.Add('INSERT INTO EVENTS (EventTypeID) VALUES (11)');
>     ExecSQL;

> <<OK up to now, but then>>

>     Open;    <<Causes the error>>

Why are you trying to Open a query after you ExecSQL it?
(Why are you using both?)

Since an INSERT  sql statement doesn't return a cursor you can use ExecSQL
with no problems.  You don't have to Open it.

Re:Error with TQuery and ExecSQL then Open


TQuery's ExecSQL and Open methods don't work together because they server
different roles.
If your sql statement returns rows use open to fetch the result-set and
navigate through it.
However, if your query is an Insert, Update, or Delete statement (or any
other sql code that does not return rows) use the ExecSQL methods to execute
the statement.

Anyway, you can never use the ExecSQL and the Open methods on the same
query.

Good Luck.

Re:Error with TQuery and ExecSQL then Open


Thank you for your responses.

I was getting my basic SQL statements mixed up. Now I understand.

Blair

Quote
bla...@istar.ca (Blair Kingsland) wrote:

Other Threads