function TPubADO.GetData(const strSQL: WideString): Recordset;
var
  ADOConn:_Connection;
  ADORDS:_Recordset;
  strConn:string;
  RecordsAffected:OleVariant;     //影响的记录条数
begin
    try
     ADOConn:=Coconnection.Create;
     ADORDS:=CoRecordset.Create;
     strConn:=MakeConnstring;   //取得连接字符串
     Adoconn.Open(strConn,User,Password,0);//以上正确
     ADORDS:=Adoconn.Execute(strSQL,RecordsAffected,adCmdText);
     if AdORDS.RecordCount>0 then //????这里 AdORDS.RecordCount=-1
        Result:=ADORDS;     finally
       ADORDS.Close;
       Adoconn.Close;
       //AdoConn.free;
       //ADORDS.free;
     end;
end;

解决方案 »

  1.   

    var 
     adoConn:ADOConnection;
     AQuery: TADOQuery;
     const ASql: string;
    begin     ADOConn:=ADOConnection.Create;
         strConn:=MakeConnstring;   //取得连接字符串
         Adoconn.Open(strConn,User,Password,0);//以上正确  with AQuery do
      begin
        Connection := ADOConn;
        if Active then Active := false;
        SQL.Clear;
        SQL.Add(ASql);
        try
             Active := true;
            //这里获取数目
        except
          on E:Exception do
            MessageDlg(E.Message, mtError, [mbOK], 0);
        end;
      end;
      

  2.   

    ADORDS:=Adoconn.Execute(strSQL,RecordsAffected,adCmdText);
    中有问题,打开游标类型不对
      

  3.   

    谢谢 wenyaoqu(qq) 请问:这里的ADO是原生的ADO,怎么设置游标???
      

  4.   

    这是MSDN上相关的一段话The returned Recordset object is always a read-only, forward-only cursor. If you need a Recordset object with more functionality, first create a Recordset object with the desired property settings, then use the Recordset object's Open method to execute the query and return the desired cursor type.
      

  5.   

    另外。。判断一个Recordset是否有记录,不应该去判断recordCount值,
    而是应该判断BOF和EOF。
      

  6.   

    把ADoConnection的
    CursorLocation 设为 clUseClient,就可以了。