我用的是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)
::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.extern CJtsjDesignerApp theApp;
或
2._ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
使用时:
1.
theApp.m_pCon->...
theApp.m_pRs->...
2.可以不变
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);
BSTR bsSql=strSql.AllocSysString();
m_pRs->Open((CComVariant)bsSql,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);