Dbedit apparently not linked to Tadoquery

Asked

Viewed 794 times

3

I have a ADOConnection, one ADODataSet, DataSource, ADOQuery, one DBGrid and a DBEdit.
The DBEdit is with the property DataField = numero.

A button with the test:

AdoQuery1.close;
AdoQuery1.SQL.Clear;
AdoQuery1.SQL.Add('select * from tabela WHERE numero=2 ');
AdoQuery1.Open;
Caption := AdoQuery1.fieldbyname('notaTeste').asString;

The SQL command worked correctly as caption shows the expected value.

But it seems that the DBGrid and the DBEdit are not bound by ADOQuery, because after given the SQL command nothing changes in Dbgrid and Dbedit.

What am I doing wrong?

Use professional and database .

  • 1

    Your question got a little confused. Right at the beginning of the text you already say that the changes made in the DBGrid are reflected in the DBEdit, then says no, and then says it works if it’s with TADODataSet. Probably your first statement that it works is with the TADODataSet, right? I don’t really remember how these components work since I work with only the component for a long time Query. But apparently the TADODataSet already manages everything, but is not very recommended. Already the component Query does not manage other types of request in this way.

  • Well, I’ll make it clear.

  • 2

    dbgrid and dbedit are linked correctly with the table. The SQL command in adoquery works. I put the results in the caption to show the test, which is working. However, when performing this select command in tadoquery, I expected only the records belonging to the selection to appear in dbgrid, as if I put the same command in the commandtext property of the tadodataset. That is, the query is executed, but dbgrid and dbedit are not updated.

  • 1

    So you need to edit your question to improve it. Because you can’t understand it. And let me correct a mistake made. Said the TADODataSet is not recommended, but I confused component and what I said was unfounded.

  • You are most likely commenting on an error that is bringing in more records then. Try taking out the TADODataSet of your test project and check the links with the DataSource.

1 answer

5


In datasets, the Datasource property is for master/detail only. The link for display and editing is: Dataset -> Datasource.Dataset -> Dbcontrol(s). Datasource

Master/Detail: Datasetmaster -> Datasource.Datasetset -> Datasetdetail.Datasource

Example(Edit/Display):

var  
  DtsVenda : TAdoQuery;  
.  
.  
DtsVenda.Close;  
// Sql só para simplificar. Sempre usar consultas parametrizadas   
DtsVenda.SQL.Text := 'select * from Venda where DatePart(month, DHVenda) = 3';
DtsVenda.Open;
DSVenda.Dataset := DtsVenda;
DbGVenda.DataSource = DSVenda;
DBEVenda.DataSource = DSVenda;

Example(Display with Master/Detail):

var  
  DtsVenda,
  DtsItemVenda : TAdoQuery;  
  DSMVenda : TDataSource;
.  
.  
DtsVenda.Close;  
// Sql só para simplificar. Sempre usar consultas parametrizadas   
DtsVenda.SQL.Text := 'select * from dbo.Venda where DatePart(month, DHVenda) = 3';
DtsVenda.Open;
DSVenda.Dataset := DtsVenda;//Até aqui tudo ok
DbGVenda.DataSource = DSVenda;
DBEVenda.DataSource = DSVenda;

DSMVenda.Dataset :=  DtsVenda; // Só para o mestre detalhe
DtsItemVenda.Close;
DtsItemVenda.SQL.Text := 'select * from dbo.ItemVenda where Id_Venda = :Id_Venda'
DtsItemVenda.Open;
DtsItemVenda.DataSource := DSMVenda;
  • Solved. In Tadoquery leave the Datasource property empty. In Tdatasource, property Tdataset type Adoquery1 (it does not offer automatically, so it took me long to realize)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.