procedure TForm1.Button5Click(Sender: TObject);
begin
ClientDataSet1.close;
ClientDataSet1.commandtext:='';
ClientDataSet1.commandtext:='select * from wangzhi where year ='+comboBox1.text ;
ClientDataSet1.open;
end;

解决方案 »

  1.   

    好像没什么问题,不过要看你year是什么类型的吧?如果不是字符串是不是要相应转一下?
      

  2.   

    SQL语法上没问题,只是类型问题
    如果year是字符型,要这样:
    'select * from wangzhi where year ='''+comboBox1.text+'''';
    如果是日期型的,就要看你的数据库了
      

  3.   

    ClientDataSet1.commandtext:='select * from wangzhi where year ='+comboBox1.text ;  改成
    ClientDataSet1.commandtext:='select * from wangzhi where year ='+QuotedStr( comboBox1.text) ; 
      

  4.   

    procedure TForm1.Button5Click(Sender: TObject);
    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的结果。
      

  5.   

    select * from wangzhi where [year]
    试试
    注意这个[year]用中括号