我使用MFC向导建立一个工程,在向导中连接了SQL数据库,最后生成了一个CRecordSet对象。请问各位我怎么使用这个CRecordSet对象调用存储过程,需要什么头文件等等

解决方案 »

  1.   

    用CRecordSet的对象可以操作command吗?
      

  2.   

    一般来说,是用Command.Execute
    执行存储过程的另外,CRecordSet对象调用存储过程,
    好像是可以的去msdn看了一下
    CRecordset::Open
    virtual BOOL Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );lpszSQLA string pointer containing one of the following: A NULL pointer.
    The name of a table.
    An SQL SELECT statement (optionally with an SQL WHERE or ORDER BY clause). 
    A CALL statement specifying the name of a predefined query (stored procedure). Be careful that you do not insert whitespace between the curly brace and the CALL keyword.看整个意思,好像是可以打开一个stored procedure的
    不过俺也没做过,不熟悉,呵呵
      

  3.   

    CDatabase   *   pDatabase   =   new   CDatabase;   
        
      pDatabase->OpenEx("DSN=ODBCName;UID=***;PWD=***",   0   );   
                
      CRecordset   rs(   pDatabase   );   
        
      SQL.Format("{call   Test('%d','%d','%d','%d')}",Time0,   Time1,   Time2,   Time3);   
        
      rs.Open(   CRecordset::dynamic,   SQL,   CRecordset::readOnly   );   
        
      if(rs.IsBOF()==0)   
      rs.MoveFirst();   //报错:提取类型超出范围   
        
      while(rs.IsEOF()==0)   
      {   
      rs.GetFieldValue(   (long)0,   strReturn   );   
          
      ....   
          
      rs.MoveNext();   
      }   
        
      rs.Close();   
        
      pDatabase->Close();   
      delete   pDatabase;