我用的是ADO连接数据库,代码如下,请各位大虾看看是不是这样的?
::CoInitialize(NULL);
_variant_t vFieldValue;
CString strFieldValue;
m_pCon.CreateInstance(__uuidof(Connection));
m_pCon->Open("DSN=mobil;Provider=MSDASQL","sa","",adConnectUnspecified );
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs->Open("select* from client",m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);还有在我编译的时候没错,可是在运行的时候会有这样的提示:
unhandled exception in 移动客户服务系统.exe(KERNEL32.DLL):(OxE06D7363;Microsoft C++ Exception)

解决方案 »

  1.   

    m_pRs->Open("select* from client",(IDispatch*)m_pCon,adOpenDynamic,adLockOptimistic,adCmdText);这样可以!
      

  2.   

    定义extern 变量
    1.extern CJtsjDesignerApp theApp;

    2._ConnectionPtr m_pConnection;
    _RecordsetPtr  m_pRecordset;
    使用时:
    1.
    theApp.m_pCon->...
    theApp.m_pRs->...
    2.可以不变
      

  3.   

    例1.
    CString strSQL = "select * from table";
    theApp.m_pRecordset.CreateInstance("ADODB.Recordset");
    theApp.m_pRecordset->Open((_bstr_t)strSQL,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
      

  4.   

    可能是在执行SQL语句的时候出问题的了
      

  5.   

    是不是这句话错了啊?构建SQL语句打开数据集还可以用什么语句啊?
    BSTR bsSql=strSql.AllocSysString();
    m_pRs->Open((CComVariant)bsSql,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);