Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Relational Databases
Expertise: Beginner
May 28, 1997

TQuery command to use to execute a SQL statement

Question:
I'm trying to delete multiple records using Tquery such as
delete from products p
   where p.shopno in
     (select shopno 
        from shops)
When I run the program, it executes the statements and deletes matching records but gives me an error message such as 'error creating cursor handle'. What is the reason and what can I do?

Answer:
The only reason I can think of for this is that instead of issuing the ExecSQL command to execute the DELETE, you're issuing the Open command. Here are a couple of rules you should follow when using SQL in Delphi:

  1. Use the Open command for a TQuery or one of its descendants when you want to return a result set from the query that will be in the form of either a cursor handle or a batch moved to a persistent data store (TTable). This includes calling stored procedures called within the context of a SQL statement (i.e., SELECT * FROM MyStoredProc).
  2. Use the ExecSQL command for a TQuery or one of its descendants when the SQL operation does not return a result set. This applies to INSERT, UPDATE and DELETE queries that are table maintenance queries.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date