Wrote an application that connects to the database and should display the data tables (so far one). On the DataModule, IBQuery (select * from clients), IBDataSource, IBDataSet, IBDataSetProvider linked them to an IBDatabase, which is in a different form. Opening a window with a DBGrid (linked by a DataSource with an IBDataSource) results in an error

IBQuery1: Cannot perform this operation on an open dataset. 

Debugging has shown that this error occurs on the line.


in the next block of code

 procedure TfmTableData.FormActivate(Sender: TObject); var openTable : TTableSpec; CountColumns : integer; I: Integer; begin openTable:=TTableSpec(DBSchema.Tables.FindComponent(fmListOfTables.Listbox1.Items.Strings[fmListOfTables.Listbox1.ItemIndex])); CountColumns:=openTable.Fields.ComponentCount; //DBGrid1.Columns.:=CountColumns; {for I := 0 to CountColumns-1 do begin DBGrid1.Columns.Add; DBGrid1.Columns[i].Title.Caption:=openTable.Fields.Components[i].Name; end; } MainWindow.IBDatabase1.Connected:=true; //IBTable1.TableName:='CLIENTS'; mydm.IBDataSet1.Close; mydm.IBQuery1.Open; mydm.IBQuery1.ExecSQL; //IBDataSet1.Open; //IBTable1. //fmTableData.DataSource1.DataSet:=IBDataset1; //fmTableData.DBGrid1.DataSource:=fmTableData.IBDataset1; end; 

    2 answers 2

    You have a problem in that you call the Open method, and then immediately also occupy ExecSQL.

     mydm.IBQuery1.Open; mydm.IBQuery1.ExecSQL; 

    You need to choose one thing. For SELECT queries use the Open method. For all others that do not return a dataset, use ExecSQL. You have in this example, an extra method ExecSQL, because Your SELECT query is in Query.

      Open superfluous, it is enough only ExecSQL

      • @savro no open is not superfluous, because without it, the message use Open for a Select Statement appears. (this also shows debugging on the mydm.IBQuery1.ExecSQL ). The reason is not in Open. Delete this answer - it is not correct. - ivan89
      • note: a frequent starter error - for queries that do not return data, call the Open method instead of ExecQuery (ExecSQL, ExecProc). The Open method is used to execute select queries. IBSQL.ExecQuery (or IBQuery.ExecSQL) is used for insert, update, delete, and execute procedure queries. ibase.ru/devinfo/sp_call.htm - vdk company