StdAfx.h 加入:#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","ADOEOF")我的程序代码:BOOL CAdo_test3Dlg::OnInitDialog()
{
CDialog::OnInitDialog(); 。。省略 // TODO: Add extra initialization here
if (FAILED(::CoInitialize(NULL))) // initialize COM
return FALSE;
_RecordsetPtr pRs = NULL; //declare recordset point
pRs.CreateInstance(_uuidof(Recordset));
//connect
// _bstr_t strCnn("Provider=SQLOLEBD.1; User ID=sa; Initial Catalog=Traffic; Data Source=CWJ");
CString sConn = "Provider=SQLOLEBD.1; User ID=sa; Initial Catalog=Traffic; Data Source=CWJ";
_bstr_t strCnn(sConn);
// open the recordset
pRs->Open("select * from operator",strCnn,adOpenDynamic,adLockReadOnly,adCmdText);
COleVariant value; //declare the value
while (!pRs->ADOEOF)
{
value = pRs->GetFields()->GetItem("name")->GetValue();
m_ctrComb.AddString(CString(value.bstrVal));
pRs->MoveNext();
}
pRs->Close();
::CoUninitialize(); //release the COM
return TRUE; // return TRUE unless you set the focus to a control
}编译无错,运行弹出对话框:Microsoft vc++ runtime libary
error runtime
program:D\works\ado_test3\debug\ado_test3.ext
This application has requested the Runtime to terminate it in a unusual way.Please contact the application's support team for more information.
{
CDialog::OnInitDialog(); 。。省略 // TODO: Add extra initialization here
if (FAILED(::CoInitialize(NULL))) // initialize COM
return FALSE;
_RecordsetPtr pRs = NULL; //declare recordset point
pRs.CreateInstance(_uuidof(Recordset));
//connect
// _bstr_t strCnn("Provider=SQLOLEBD.1; User ID=sa; Initial Catalog=Traffic; Data Source=CWJ");
CString sConn = "Provider=SQLOLEBD.1; User ID=sa; Initial Catalog=Traffic; Data Source=CWJ";
_bstr_t strCnn(sConn);
// open the recordset
pRs->Open("select * from operator",strCnn,adOpenDynamic,adLockReadOnly,adCmdText);
COleVariant value; //declare the value
while (!pRs->ADOEOF)
{
value = pRs->GetFields()->GetItem("name")->GetValue();
m_ctrComb.AddString(CString(value.bstrVal));
pRs->MoveNext();
}
pRs->Close();
::CoUninitialize(); //release the COM
return TRUE; // return TRUE unless you set the focus to a control
}编译无错,运行弹出对话框:Microsoft vc++ runtime libary
error runtime
program:D\works\ado_test3\debug\ado_test3.ext
This application has requested the Runtime to terminate it in a unusual way.Please contact the application's support team for more information.
m_pConnetion.Open();先建立连接再pRs->Open();