我写了这样的一个查询窗体,(注:combobox1中的值为bookin表中的几个字段)
我现在想实现,当我从combobox1中选择一个字段,然后再在edit1中输入内容
单击"确定"按钮来查询想要找的内容,然后把查询到的内容在dbgrid中显示,
以下写的代码也不知道那里有问题
请指导,谢谢!
     with dm.query2 do
      begin
          close;
          sql.Clear;
          sql.Add('select * from bookin where combobox1.text=:E');
          Parameters.ParamByName('E').Value:=trim(edit1.Text);
          prepared:=true;
          open;
      end;

解决方案 »

  1.   

    -->     sql.Add('select * from bookin where combobox1.text=:E');
    sql.Add( 'Select * From bookin where ' + combobox1.text + '=:E' );
      

  2.   

    with dm.query2 do
    begin
      close;
      sql.Clear;
      sql.Add('select * from bookin where ''' + combobox1.text + ''' = :E');
      Parameters.ParamByName('E').Value:=trim(edit1.Text);
      prepared:=true;
      open;
    end;
      

  3.   

    faint 
    楼上的,你楼上的错了,哪有在查询字段两边加引号的
    而且如果QUERY用Parameters的,即使是字符串也不用加引号在原来的SQL语句的
      

  4.   

    querystr:=combobox1.text+'='+''''+edit1.Text+'''';adodataset.CommandText:='select * from MaintManView where '+querystr;这样就不会错了嘛!错拉来找我,^_^!
      

  5.   

    with dm.query2 do
    begin
      close;
      sql.Clear;
      sql.Add('select * from bookin where ' + combobox1.text + ' = :E');
      Parameters.ParamByName('E').Value:=trim(edit1.Text);
      prepared:=true;
      open;
    end;or with dm.query2 do
    begin
      close;
      sql.Clear;
      sql.Add('select * from bookin where ' + combobox1.text + ' = '+''''+trim(edit1.Text)+'''');
       prepared:=true;
      open;
    end;
      

  6.   

    var
      Str: String;
    begin
      with dm.query2 do
      begin
        close;
        sql.Clear;
        sql.Add('select * from bookin where  Str = :E');
        Parameters.ParamByName('E').Value:=trim(edit1.Text);
        prepared:=true;
        open;
      end;
    end;      //  这样就不用担心引号的问题了;  ~—~
      

  7.   

    这样写
    params.ParamByName('E').Value:=trim(edit1.Text);