Executing a query at runtime
Go Up to Executing a query
To execute a query at runtime, use one of the following methods:
Openexecutes a query that returns a result set, such as with theSELECTstatement.ExecSQLexecutes a query that does not return a result set, such as with theINSERT,UPDATE, orDELETEstatements.
- Note: If you do not know at design time whether a query will return a result set at runtime, code both types of query execution statements in a try...except block. Put a call to the
Openmethod in the try clause. This allows you to suppress the error message that would occur due to using an activate method not applicable to the type of SQL statement used. Check the type of exception that occurs. If it is other than anENoResultexception, the exception occurred for another reason and must be processed. This works because an action query will be executed when the query is activated with theOpenmethod, but an exception occurs in addition to that.
try
IBQuery2.Open;
except
on E: Exception do
if not (E is ENoResultSet) then
raise;
end;