代码这样写有问题,这样改一下试试
procedure TXMGZBGCX.Button1Click(Sender: TObject);
var
s1,s2: string;
cSelectsql : string;
begin
// s1 := DataLocateComboBox1.DataField;
// s2 := DataLocateComboBox2.DataField;
//s1,s2 的值应该通过DataLocateComboBox1,DataLocateComboBox2所绑定的数据集得到,比如
// DataLocateComboBox1绑定的数据集代理是DataSetBroker1,关键字段是FID
// DataLocateComboBox1绑定的数据集代理是DataSetBroker2,关键字段是FID
s1 := DataSetBroker1.DataSet.FieldByName('FID')asString;
s2 := DataSetBroker2.DataSet.FieldByName('FID')asString;
cSelectsql := 'select * from IT_WORKREPORT where FPostDept = '''+s1+''' and FPoster = '''+s2+'''';
dsbmaster.DataSet.open;
if dsbmaster.DataSet.RecordCount >= 0 then
begin
TSQLDataSet(dsbmaster.DataSet).SQLFilter := cSelectsql;
TSQLDataSet(dsbmaster.DataSet).SQLFiltered := True;
// dsbmaster.DataSet.close; 这一句不应该要了
end;
end; |