主题:[讨论]VC++ 采用ADO进行数据库访问 遇到的错误 请教高人!
代码:
void Ctransaction::sqlInsert()
{
CString strSQL;
strSQL="select * from transactionRecord";
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes=m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes=m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),((CMy03App*)AfxGetApp())->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
m_pRecordset->AddNew();
CString str;
m_pRecordset->PutCollect("transactionType",_variant_t(transactionType));
m_pRecordset->PutCollect("transactionSubject",_variant_t(transactionSubject));
m_pRecordset->PutCollect("transactionDate",_variant_t(transactionDate));
m_pRecordset->PutCollect("content",_variant_t(content));
m_pRecordset->Update();
}
}
错误:
1.error C2039: 'm_pConn' : is not a member of 'CMy03App'
2.error C2228: left of '.GetInterfacePtr' must have class/struct/union type
请教 怎么改正。
void Ctransaction::sqlInsert()
{
CString strSQL;
strSQL="select * from transactionRecord";
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
hTRes=m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes=m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),((CMy03App*)AfxGetApp())->m_pConn.GetInterfacePtr(),adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
m_pRecordset->AddNew();
CString str;
m_pRecordset->PutCollect("transactionType",_variant_t(transactionType));
m_pRecordset->PutCollect("transactionSubject",_variant_t(transactionSubject));
m_pRecordset->PutCollect("transactionDate",_variant_t(transactionDate));
m_pRecordset->PutCollect("content",_variant_t(content));
m_pRecordset->Update();
}
}
错误:
1.error C2039: 'm_pConn' : is not a member of 'CMy03App'
2.error C2228: left of '.GetInterfacePtr' must have class/struct/union type
请教 怎么改正。