DBGrid上面有ADOTable、ADOQuery,DataSource的dataset是ADOTable;向数据库中添加数据用的是ADOTable;然后查询的时候用ADOTable不好用,所以改用ADOQuery进行查询,但是查询的结果集怎么显示在DBGrid中呢?
//-------------------------------------------------------------------------------------------------
Form1.ADOQuery1.Close;
     Form1.ADOQuery1.SQL.Clear;
     Form1.ADOQuery1.SQL.Text:='select userID from userInfo where userID=:id and userName=:name';
     Form1.ADOQuery1.Parameters.ParamByName('id').Value:=strtoint(Edit1.Text);
     Form1.ADOQuery1.Parameters.ParamByName('name').Value:=trim(Edit2.Text);
     Form1.ADOQuery1.ExecSQL;
     Form1.ADOQuery1.Open;
     if form1.ADOQuery1.RecordCount<>0 then
     begin
           close;
           id:=Form1.ADOQuery1.FieldByName('userID').Value;
           with Form1.ADOQuery1 do
           begin
              close;
              SQL.Clear;
              SQL.Add('select * from userInfo where userID=:id');
              ExecSQL;
              open;
              Active:=true;
           end;
           form1.ADOTable1.Recordset:=form1.ADOQuery1.Recordset;
           Form1.ADOTable1.Open;
     end;
//-----------------------------------------------------------------------------------------
本来想将ADOQurey查询的结果集赋值给ADOTable,但是这样显示出来是空结果-_-|||

解决方案 »

  1.   

     一样的,datasourse连接adoquery
      

  2.   

    问题是连接了adoquery后,添加数据的时候,总是会刷新页面,所以添加数据的时候我觉得用ADOtable好一点,在点击查询时,可以修改datasource的dataset嘛?修改了之后好像不行
      

  3.   

    好像这个语句
    SQL.Add('select * from userInfo where userID=:id');
    应该改写如下
    SQL.Add('select * from userInfo where id='+trim(userID)+')';