用mfc ado链接数据库打开recordset时提示“无效指针”?

在用Recordset类的open函数时不能打开recordset,代码如下:
_bstr_t vSQL;
vSQL="select * from student";
(断点处)m_pRecordset->Open (vSQL,m_pConnection.GetInterfacePtr (),adOpenDynamic,adLockOptimistic,adCmdText);

所有代码如下:
void CrecordsettestDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
::CoInitialize (NULL);
try
{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect="Provider=SQLOLEDB.1;Password=27910230;Persist Security Info=True;User ID=sa;Initial Catalog=ODBC test;Data Source=HOTSAUCE-PC;";
m_pConnection->Open (strConnect,"","",adModeUnknown);
if(m_pConnection->State ==adStateOpen)
{
m_pConnection.CreateInstance (_uuidof(Recordset));
_bstr_t vSQL;
vSQL="select * from student";
m_pRecordset->Open (vSQL,m_pConnection.GetInterfacePtr (),adOpenDynamic,adLockOptimistic,adCmdText);
m_pRecordset->MoveFirst ();
id=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect ("学号");
name=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect ("姓名");
stu_class=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect ("班级");
}
else MessageBox("fuck ! I gonna try again....");
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage ());
}
}
求各位大神帮忙。。。

DBName是数据库名称,这个是写在一个类中的,m_pRecordsetPtr, m_pConnection, m_pConnection,SXBBQG
温馨提示:内容为网友见解,仅供参考
无其他回答

用mfc ado链接数据库打开recordset时提示“无效指针”?
DBName是数据库名称,这个是写在一个类中的,m_pRecordsetPtr, m_pConnection, m_pConnection,SXBBQG

相似回答
大家正在搜