AnyDAC
ContentsIndexHome
PreviousUpNext
TADDataSet.OpenOrExecute Method

Executes SQL command and optionally opens dataset.

Group
Links

True, if a command returned result set.

Use OpenOrExecute method, if you does not know - will command return result set or not. The most common case for that is the execution of an ad hoc query. 

The OpenOrExecute method executes SQL command. And if command returns any result set, then this method opens dataset. The method supplements Open and Execute / ExecSQL / ExecProc methods:

  • the Open method raises an exception "[AnyDAC][Phys]-308. Command must return row set", if a command does not return result set, like a INSERT;
  • the Execute / ExecSQL / ExecProc methods raise an exception "[AnyDAC][Phys]-310. Cannot execute command returning results set", if a command returns result set, like a SELECT.

At OpenOrExecute call a "[AnyDAC][Phys]-308" may be raised, but it will be not propagated out of the method.

function OpenOrExecute: Boolean;
ADQuery1.Disconnect(True);
ADQuery1.SQL.Assign(Memo1.Lines);
if ADQuery1.OpenOrExecute then begin
  PageControl1.ActivePage := DataGridPage;
  DataGridPage.TabVisible := True;
end
else
  DataGridPage.TabVisible := False;
What do you think about this topic? Send feedback!