帮我看看这段代码有什么错?用ado开发数据库,只要在combobox中显示某个字段的值,编译通过,运行时“数据库连接失败”,什么原因呢?
BOOL CMyPropertyPage1::OnShowWindow(BOOL bShow, UINT nStatus)
{
--CPropertyPage::OnShowWindow(bShow, nStatus);
--// open database
--_ConnectionPtr m_pConnection;
--HRESULT hr;
--try
--{
----hr = m_pConnection.CreateInstance("ADODB.Connection");//Connection对象
----if(SUCCEEDED(hr))
----{
------hr =m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=道路指标.mdb","","",adModeUnknown);
----}
--}
--catch(_com_error e)///捕捉异常
--{
----CString errormessage;
----errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
----AfxMessageBox(errormessage);///显示错误信息
----return TRUE;
--}
--_RecordsetPtr m_pRecordset;
--_variant_t RecordsAffected=(long)0;
--m_pRecordset = m_pConnection->Execute("SELECT * FROM 公路等级",&RecordsAffected,adCmdText);// 公路等级为表的名字
--_variant_t Holder;
--try
--{
----while(!m_pRecordset->adoEOF)
----{
------Holder = m_pRecordset->GetCollect("Highway_grade");
------if(Holder.vt!=VT_NULL)
--------m_grade.AddString((char*)_bstr_t(Holder));
------m_pRecordset->MoveNext();
----}
--}
--catch(_com_error * e)
--{
----CString Error = e->ErrorMessage();
----AfxMessageBox(e->ErrorMessage());
--}
--m_pRecordset->Close();///关闭记录集
--m_pConnection->Close();///关闭数据库连接
--return TRUE; // return TRUE unless you set the focus to a control
-- // EXCEPTION: OCX Property Pages should return FALSE
}
帮我看看这段代码有什么错?用ado开发数据库,只要在combobox中显示某个字段的值,编译通过,运行时“数据库连接失败”,什么原因呢?m_grade为一个组合框控件变量。