TDBGrid does not update data in delphi

0
Well, I'm doing a system for a library and in the book search grid that when typing the book id in txtbox it updates and shows the results on the grid, but the grid is not updating and the data is still on the grid and do not change. If anyone knows what is thank you from now on.

    procedure Tfrm_alocar.BitBtn1Click(Sender: TObject);
    var parametro:integer;
    begin

      parametro := strtoint(txt_livro.Text);

      Form_dados.Modulo_Dados.Query_livros.Close;
      Form_dados.Modulo_Dados.Query_livros.sql.Clear;
      Form_dados.Modulo_Dados.Query_livros.sql.Add('select * from livros where id = :parametro');
     Form_dados.Modulo_Dados.Query_livros.Parameters.ParamByName('parametro').Value := parametro;
      Form_dados.Modulo_Dados.Query_livros.Open;

      GridLivros.Update;
      GridLivros.Refresh;

    end;
    
asked by anonymous 18.03.2017 / 14:33

1 answer

1

I have a hunch about what might be happening. You are updating the query_book component. Maybe the grid is bound to a ClientDataset and not to the query_books. It is common to make the connection database - > query - > datasetprovider - > clientdataset - > datasource - > dbgrid. If this is the case, you should do close in ClientDataset and not in query_books. More or less this:

cds.Close;
qry.ParamByName('parametro').AsInteger := parametro;
cds.Open;
    
18.03.2017 / 22:19