DBEdit apparently not linked to TADOQuery

3

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

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 because caption shows the expected value.

But it seems that DBGrid and DBEdit are not bound to ADOQuery , because after giving the SQL command nothing changes in DBGrid and DBEdit.

What am I doing wrong?

Use professional and bank sql-server-2012 .

    
asked by anonymous 21.04.2014 / 02:08

1 answer

5

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

Master / Detail: Master Dataset - > DataSource.DatasetSet - > DatasetDataSource

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 (Master / Detail View):

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;
    
24.04.2014 / 20:45