我是delphi中的Interbase新手。谁能告诉我如何正确使用Interbase从编码火鸟数据库查询数据?我试过这样做:
procedure TfJM00001.af_search;
var
i : integer;
qryQuery : TIBdataset;
sql : string;
begin
Try
qryQuery := TIBDataSet.Create(nil);
qryQuery.Database := IBDatabase1;
qryQuery.Transaction := qryQuery.Database.DefaultTransaction;
sql := ' select pro.pro_id, pro.pro_nm, cat.cat_nm, div.division_nm, pro.price, pro.weight, pro.qty , typ.type_nm, pro.images ' + #13#10 +
' from product pro ' +#13#10+
' left join division div on div.division_id = pro.division_id ' +#13#10+
' left join category cat on cat.cat_id = pro.cat_id ' +#13#10+
' left join tbl_type typ on typ.type_id = pro.type_id; ' ;
try
qryQuery.Close;
qryQuery.SelectSQL.Text := sql;
qryQuery.Open;
if qryQuery.RecordCount < 0 then exit;
with cxGrid1BandedTableView1.DataController do
begin
RecordCount := 0;
BeginUpdate;
while not(qryQuery.Eof) do
begin
i := AppendRecord;
SetValue( i, col_Pro_Id.Index ,qryQuery.FieldByName('PRO_ID').AsString);
SetValue( i, col_Pro_NM.Index ,qryQuery.FieldByName('PRO_NM').AsString);
SetValue( i, col_Cat_NM.Index ,qryQuery.FieldByName('CAT_NM').AsString);
SetValue( i, col_Type_NM.Index ,qryQuery.FieldByName('TYPE_NM').AsString);
SetValue( i, col_Price.Index ,qryQuery.FieldByName('PRICE').AsString);
// SetValue( i, Col_Description.Index ,qryQuery.FieldByName('PRO_NM').AsString);
SetValue( i, Col_Weight.Index ,qryQuery.FieldByName('WEIGHT').AsString);
SetValue( i, col_Qty.Index ,qryQuery.FieldByName('QTY').AsString);
SetValue( i, col_Division.Index ,qryQuery.FieldByName('DIVISION_NM').AsString);
// SetValue( i, col_register_date.Index ,qryQuery.FieldByName('PRO_NM').AsString);
//SetValue( i, col_Compound.Index ,qryQuery.FieldByName('Images').AsVariant);
qryQuery.Next;
end;
EndUpdate;
end;
except on
e : exception do
begin
showmessage('Error Message : ' + e.Message);
end;
end;
Finally
qryQuery.Database.DefaultTransaction.Active := False;
end;
end;
你应该将查询连接到数据源,使用DBBandedTableView并将DBBandedTableView链接到查询。cxGrid1BandedTableView1。数据控制器不是这样填充的