请帮我看看下面的程序哪儿有错!!
程序编译时能通过.在执行时总是出现异常(too few paramters)!!
我用的是ACCESS 2000 ,ODBC
procedure Tyexport.Button1Click(Sender: TObject);
var
str:string;
begin
if (checkbox1.Checked=false) and (checkbox2.Checked=false) then
begin
showmessage('请选择查询条件');
end
else
begin
DataSource1.DataSet:=Query1;
Dbgrid1.DataSource:=Datasource1;
with Query1 do
begin
DatabaseName:='ypgl';
close;
sql.clear;
str:='select * from rkb ' ;
if checkbox1.Enabled=true then
begin
str:=str+'where chdw=combobox1.text';
end;
if checkbox2.Checked=true then
begin
str:=str+'where xsrq=datetostr(datetimepicker1.date)';
end;
if (checkbox1.Checked=true ) and  checkbox2.Checked=true then
begin
 str:=str+'where xsrq=datetostr(datetimepicker1.date) and  chdw=combobox1.text';
end;
sql.add(str);
prepare;
open;
end;
end;
end;

解决方案 »

  1.   

    str:=str+'where chdw=combobox1.text';
    應為:
      str:=str + 'where chdw=' + '''' + combobox1.text + '''';str:=str+'where xsrq=datetostr(datetimepicker1.date)';
    應為:
      str:=str + 'where xsrq=' + '''' + datetostr(datetimepicker1.date) + ''''';
      

  2.   

    procedure Tyexport.Button1Click(Sender: TObject);
    var
    str:string;
    begin
    if (checkbox1.Checked=false) and (checkbox2.Checked=false) then
    begin
    showmessage('请选择查询条件');
    end
    else
    begin
    DataSource1.DataSet:=Query1;
    Dbgrid1.DataSource:=Datasource1;
    with Query1 do
    begin
    DatabaseName:='ypgl';
    close;
    sql.clear;
    str:='select * from rkb ' ;
    if checkbox1.Enabled=true then
    begin
    str:=str+'where chdw=combobox1.text';//error//str:=str+'where chdw='''+combobox1.text+'''';//后面还有许多类似的错误
    end;
    if checkbox2.Checked=true then
    begin
    str:=str+'where xsrq=datetostr(datetimepicker1.date)';
    end;
    if (checkbox1.Checked=true ) and  checkbox2.Checked=true then
    begin
     str:=str+'where xsrq=datetostr(datetimepicker1.date) and  chdw=combobox1.text';
    end;
    sql.add(str);
    prepare;
    open;
    end;
    end;
    end;
      

  3.   

    SQL语句里面不能直接调用delphi函数,必须传给他值