这段代码该怎么改???
var
 r1,r2,r3:char;
begin
    adoquery1.close;
    adoquery1.sql.Clear;
    adoquery1.sql.add('select*  from caichan c ' ) ;
    adoquery1.sql.add('where (c.sushelou_id=:r1) and (c.louceng_id=:r2)
                            and (c.sushe_id=:r3)')  ;
    adoquery1.parameters.ParamByname('r1').value:=combobox1.Text;
    adoquery1.parameters.ParamByname('r2').value:=combobox2.Text;
    adoquery1.parameters.ParamByname('r3').value:=combobox3.Text;
    adoquery1.open;
end;
错误:
[Error] Unit4.pas(54): Unterminated string
[Error] Unit4.pas(55): Undeclared identifier: 'c'
[Error] Unit4.pas(55): Expression expected but ':' found

解决方案 »

  1.   

    adoquery1.sql.add('where (c.sushelou_id=:r1) and (c.louceng_id=:r2)
                                and (c.sushe_id=:r3)')  ;把这一句改一下
    adoquery1.sql.add('where (c.sushelou_id:=r1) and (c.louceng_id:=r2)
                                and (c.sushe_id:=r3)')  ;还有,你把语句中的C全去掉试一下
      

  2.   

    补充,
    var
       r1,r2,r3:string;要定意为string类型
      

  3.   

    var
     r1,r2,r3:char; //首先声明这些变量是没有必要,删除
    begin
        adoquery1.close;
        adoquery1.sql.Clear;
    {    adoquery1.sql.add('select*  from caichan c ' ) ;
        adoquery1.sql.add('where (c.sushelou_id=:r1) and (c.louceng_id=:r2)
                                and (c.sushe_id=:r3)')  ;}
    //改为
        ADOQuery1.sql.add('select * from caichan ');
        ADOQuery1.sql.add('where sushelou_id=:r1 and louceng_id=:r2
                                and sushe_id=:r3');
    //后面的最好:
        adoquery1.parameters.ParamByname('r1').value:=Trim(combobox1.Text);
        adoquery1.parameters.ParamByname('r2').value:=Trim(combobox2.Text);
        adoquery1.parameters.ParamByname('r3').value:=Trim(combobox3.Text);
        adoquery1.open;
    end;
      

  4.   

    其实还有更简单的写法:
    begin
      with ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.add('select * from caichan ');
        sql.add('where sushelou_id=:r1 and louceng_id=:r2
                                and sushe_id=:r3');
        parameters.ParamByname('r1').value:=Trim(combobox1.Text);
        parameters.ParamByname('r2').value:=Trim(combobox2.Text);
        parameters.ParamByname('r3').value:=Trim(combobox3.Text);
        open;
    end;
      

  5.   

    var
     sqlstr:string;
    begin
       sqlstr:='select*  from caichan where sushelou_id ='''+combobox1.Text+''' and louceng_id ='''+combobox2.Text+''' and sushe_id = '''+combobox3.Text+''''; 
       with adoquery1 do
        begin
        close;
        sql.Clear;
        sql.add(sqlstr) ;
        open;
    end;
      

  6.   

    to 星云星: 动态查询应该用 =:
    to 蜡笔小新:你的建议和没改结果都差不多,错误都是一样的
      其实我也想进步:你 的代码已经可以了,能不能告诉我的代码错在哪?怎么改?