Board index » delphi » ERROR : 'error creating cursor handle'

ERROR : 'error creating cursor handle'

Hi,

I use this code to delete some records from a database:

Query.Active := true;
Query.SQL.Clear();

SQLSTR := 'DELETE FROM [TableName] WHERE [Field] > ''' + Datum + '''';
Query.SQL.Add(SQLSTR);
Query.ExecSQL();
Query.Active := true;

but when the Query.Active is set to true, I get the error:

    'Error creating cursor handle'

What wrong with this, and what is the solution to solve this problem?
Thanx for helping me !!!!

Sander

 

Re:ERROR : 'error creating cursor handle'


Quote
Sander van Es wrote:
> Hi,

> I use this code to delete some records from a database:

> Query.Active := true;
> Query.SQL.Clear();

> SQLSTR := 'DELETE FROM [TableName] WHERE [Field] > ''' + Datum + '''';
> Query.SQL.Add(SQLSTR);
> Query.ExecSQL();
> Query.Active := true;

Why do You want to open the query? Setting Active := True has the same
effect as Query.Open; For queries that do not return recordset You
should use only Query.ExecSQL;

I would write the above as follows:

Query.Active := False; // You had True here....
Query.SQL.Text :=
     'DELETE FROM [TableName] WHERE [Field] > ''' + Datum + '''';
Query.ExecSQL();

--
Gert

Re:ERROR : 'error creating cursor handle'


Thanx for helping !!!

Yes sorry, the code I use whas wrong, but now I have used your code and I
get the same error : error creating cursor handle
I get the error when I set Query.Active := true, because I have to show
something in a DBGrid, that's why I set this property active.

But what else do I wrong ?

Sander

Quote
"Gert Kello" <G...@gaiasoft.ee> wrote in message

news:3D0F2680.6010308@gaiasoft.ee...
Quote
> Sander van Es wrote:
> > Hi,

> > I use this code to delete some records from a database:

> > Query.Active := true;
> > Query.SQL.Clear();

> > SQLSTR := 'DELETE FROM [TableName] WHERE [Field] > ''' + Datum + '''';
> > Query.SQL.Add(SQLSTR);
> > Query.ExecSQL();
> > Query.Active := true;

> Why do You want to open the query? Setting Active := True has the same
> effect as Query.Open; For queries that do not return recordset You
> should use only Query.ExecSQL;

> I would write the above as follows:

> Query.Active := False; // You had True here....
> Query.SQL.Text :=
>      'DELETE FROM [TableName] WHERE [Field] > ''' + Datum + '''';
> Query.ExecSQL();

> --
> Gert

Re:ERROR : 'error creating cursor handle'


Quote
> Yes sorry, the code I use whas wrong, but now I have used your code and I
> get the same error : error creating cursor handle
> I get the error when I set Query.Active := true, because I have to show
> something in a DBGrid, that's why I set this property active.

"DELETE" query does not return record set - so, You can't show something
on the grid. There is nothing to be shown....

If You want to show something, use another TQuery for "SELECT" statement
with identical where clause.... You have to open it before the delete
query :)

--
Gert

Other Threads