procedure TForm1.Button5Click(Sender: TObject);
begin
ClientDataSet1.close;
ClientDataSet1.commandtext:='';
ClientDataSet1.commandtext:='select * from wangzhi where year ='+comboBox1.text ;
ClientDataSet1.open;
end;
begin
ClientDataSet1.close;
ClientDataSet1.commandtext:='';
ClientDataSet1.commandtext:='select * from wangzhi where year ='+comboBox1.text ;
ClientDataSet1.open;
end;
如果year是字符型,要这样:
'select * from wangzhi where year ='''+comboBox1.text+'''';
如果是日期型的,就要看你的数据库了
ClientDataSet1.commandtext:='select * from wangzhi where year ='+QuotedStr( comboBox1.text) ;
begin
Data.close;
Data.commandtext:='';
Data.commandtext:='select * from wangzhi where year ='+QuotedStr( ComboBox1.text);
Data.open;
Edit1.Text:=IntToStr(Data.RecordCount);
end;
year是string类型,查询后DBGrid和Edit1.Text显示的都不是欲查询的结果,而是select * from wangzhi的结果。
试试
注意这个[year]用中括号