operation cannot be performed on an inactive dataset. lazarus / 16-Databases ---------------------------------------------------------------------- marcm · 2021-03-27 19:48 Hello everyone! I have a form with some Dbedt. and when I start the form I wanted the program to check if the ID of this Dbedt exists in the corresponding table. If this data exists there, the table will be opened and the data placed in the subsequent Dbedts. However, it turns out that when running the application and showing the form it gives the error message below: operation cannot be performed on an inactive dataset. Follow the code used. procedure TfrmS21teste . FormShow ( Sender : TObject ); begin     if dbeditId.text <> '' then         dm.tbSetembro.Close;         dm.tbSetembro.SQL.Clear;         dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = frmS21teste.dbeditId.Text';     if dm.tbSetembro.RecordCount >= 1 then       dm.tbSetembro.Open; end; Sorry for the bad English, tanks Marcm ---------------------------------------------------------------------- speter · 2021-03-27 23:31 Your indenting seems confusing: Quote from: marcm on March 27, 2021, 08:48:49 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmS21teste . FormShow ( Sender : TObject );begin    if dbeditId.text <> '' then        dm.tbSetembro.Close;     dm.tbSetembro.SQL.Clear;  dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = frmS21teste.dbeditId.Text';     if dm.tbSetembro.RecordCount >= 1 then      dm.tbSetembro.Open;end; did you mean: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmS21teste . FormShow ( Sender : TObject );begin    if dbeditId.text <> '' then      begin        dm.tbSetembro.Close;        dm.tbSetembro.SQL.Clear;        dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = frmS21teste.dbeditId.Text';      end;     if dm.tbSetembro.RecordCount >= 1 then      dm.tbSetembro.Open;end; also, if " frmS21teste.dbeditId.Text" is a variable in your program (not a field in the db) I think that line should be: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = '+frmS21teste.dbeditId.Text;assuming idCliente is a number in the db (if it is a text field you need to enclose it in double quotes). cheers S. ---------------------------------------------------------------------- paweld · 2021-03-28 05:12 you are trying to read the RecordCount before open the query. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmS21teste . FormShow ( Sender : TObject );begin  if dbeditId.Text = '' then    exit;  if dm.tbSetembro.Active then //close query if active    dm.tbSetembro.Close;  //dm.tbSetembro.SQL.Clear;  //if you set Sql.Text do no need SQL.Clear  dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = :id';  dm.tbSetembro.ParamByName('id').AsString := frmS21teste.dbeditId.Text;  dm.tbSetembro.Open;  if dm.tbSetembro.RecordCount = 0 then  //RecordCount is available only when query is Active    dm.tbSetembro.Close;end; ---------------------------------------------------------------------- marcm · 2021-03-28 14:53 Hi, thanks for reply! now the error change. SQL Error: database is locked I want to do a search on the table and if it contains data I want it to display in the DBEdits, but if there is no data in the table, it opens and let me enter the values ​​that I type in the DBedits. Here is the code that displays the error: procedure TfrmS21teste . FormShow ( Sender : TObject ); begin     if dbeditId.text <> '' then        if dm.tbSetembro.Active then //close query if active         //dm.tbSetembro.Close;         //dm.tbSetembro.SQL.Clear;         dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = :id';         dm.tbSetembro.ParamByName('id').AsString := frmS21teste.dbeditId.Text;         dm.tbSetembro.Open;     if dm.tbSetembro.RecordCount >= 1 then       dm.tbSetembro.Open end; ---------------------------------------------------------------------- paweld · 2021-03-29 05:44 if you want to search for a record in an open table use Locate function, eg. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  id: Integer;begin  if TryStrToInt(editId.Text, id) then  begin    if not tbSeptembre.Locate('idCliente', id, []) then      ShowMessage('idCliente not found!');  end  else    ShowMessage(editId.Text + ' is not a number'); ---------------------------------------------------------------------- egsuh · 2021-03-29 11:45 You cannot do anything on closed (inactive) dataset. First you have to open it and then do whatever you want. I think you'd better use TEdit,  instead of TDBEdit --- DBEdit is linked to a field, and displays (and edits) the content of the field automatically. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         dm.tbSetembro.Close;        dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = :id';        dm.tbSetembro.ParamByName('id').AsString := frmS21teste.dbeditId.Text;        dm.tbSetembro.Open;         if dm.tbSetembro.IsEmpty then dm.tbSetembro.Close        else begin               // do whatever you want        end; ---------------------------------------------------------------------- marcm · 2021-03-29 21:13 tks egsuh I managed to make it work with the code you indicated. Now he is doing what I wanted, putting the data in the Dbedits of the corresponding months. I will implement the other months now and see if everything is right. Thank you again! Can Close the Post   dm.tbSetembro.Close;   dm.tbSetembro.SQL.Text:= 'SELECT * FROM setembro WHERE idCliente = :id';   dm.tbSetembro.ParamByName('id').AsString := frmS21teste.dbeditId.Text;   dm.tbSetembro.Open;   dm.tbOutubro.Close;   dm.tbOutubro.SQL.Text := 'SELECT * FROM outubro WHERE idCliente = :id' ;   dm.tbOutubro.ParamByName('id').AsString := frmS21teste.dbeditId.Text;   dm.tbOutubro.Open;