Search code examples
sqldelphiadotadoquery

DELPHI ADOQuery - detect if dataset will be returned


I'm struggling with correct procedure for executing SQL query.

Basically, I have text field where user can enter SQL code and program will execute it. Unfortunately, I don't know if the dataset will be returned, so I cant tell which function to use: ADOQuery.Open or ADOQuery.ExecSQL

But I need to make some calculations if there is results returned.

Is there any way of predicting if query will return some result or if it is UPDATE only ... how to handle this situation ?


Solution

  • Forget about TADOQuery, TADOTable, TADOStoredProc. They are components designed to ease porting from applications using the BDE that used their counterparts. In your situation you can use TADOCommand, its Execute() method will return a recorset when needed, and you can access it via a TADODataset assigning Execute() return value to its RecordSet property.