定义
_RecordsetPtr m_pRs 出错
摘录:
1.TestDoc.h
/////////////////////////////////////////////////////////////////
private: IADORecordBinding* m_piAdoRecordBinding;
CCustomRs m_rsRecSet;
CString m_strConnection;
CString m_strCmdText;
_RecordsetPtr m_pRs;2.TestDoc.cpp
//////////////////////////////////////////////////////////////////
BOOL CTestDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;

m_strConnection=_T("Provider=MSDASQL.1;Data Source=mytest");
m_strCmdText=_T("select * from mytest");         ////////////就是下面这个m_pRS////////////////
m_pRs=NULL;
m_piAdoRecordBinding=NULL; // TODO: add reinitialization code here
// (SDI documents will reuse this document) return TRUE;
}3.Debug showing
////////////////////////////////////////////////////////////////
Compiling...
TestDoc.cpp
h:\my program\vc++\mfc\test\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2146: syntax error : missing ';' before identifier 'm_pRs'
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: 'm_pRs' : missing storage-class or type specifiers
H:\My program\VC++\MFC\Test\TestDoc.cpp(51) : error C2065: 'm_pRs' : undeclared identifier
Generating Code...
Compiling...
Test.cpp
h:\my program\vc++\mfc\test\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2146: syntax error : missing ';' before identifier 'm_pRs'
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: 'm_pRs' : missing storage-class or type specifiers
Generating Code...
Compiling...
TestView.cpp
h:\my program\vc++\mfc\test\debug\msado15.tlh(409) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2146: syntax error : missing ';' before identifier 'm_pRs'
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
h:\my program\vc++\mfc\test\testdoc.h(59) : error C2501: 'm_pRs' : missing storage-class or type specifiers
Generating Code...
Error executing cl.exe.Test.exe - 10 error(s), 3 warning(s)请问如何进行改正,谢谢!

解决方案 »

  1.   

    头文件没有加进来吧!!
    #include "comdef.h"
    #import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","ISEOF")然后初始化com组件
    if(FAILED(::CoInitialize(NULL)))
      return;
    m_pConnection.CreateInstance(_uuidof(Connection));
    m_pRecordset.CreateInstance(_uuidof(Recordset));
    然后你在定义就行了
      

  2.   

    1、使用预处理指令#import
    #import "C:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    但要注意不能放在stdAfx.h文件的开头,而应该放在所有include指令的后面。否则在编译时会出错。
    程序在编译过程中,VC++会读出msado15.dll中的类型库信息,自动产生两个该类型库的头文件和实现文件msado15.tlh和msado15.tli(在您的Debug或Release目录下)。在这两个文件里定义了ADO的所有对象和方法,以及一些枚举型的常量等。我们的程序只要直接调用这些方法就行了,与使用MFC中的COleDispatchDriver类调用Automation对象十分类似。
      

  3.   

    #import "C:\Program Files\Common Files\System\ADO\msado15.dll" named_guids rename("EOF","adoEOF"), rename("BOF","adoBOF")
    using namespace ADODB; 如果没有该句需要
    m_pConnection.CreateInstance(_uuidof(ADODB::Connection));
      

  4.   

    #import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","adoEOF")
    AfxOleInit();