|
小弟初学数据库,想用ado连接ODBC的數据源,但shi怎么也连jie不上。以下是有關代码,请各位前辈高手指点。
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
{
hr=m_pConnection->Open(_bstr_t("rovider=Microsoft.Jet.OLEDB.4.0;\
Data Source=C:\Documents and Settings\Administrator\桌面\ADOMFC1\data.mdb;"),
_bstr_t(""),
_bstr_t(""),
adModeUnknown);
if(SUCCEEDED(hr))
m_IsConnectionOpen=TRUE;
}
}
catch (_com_error &e)
{
//Get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE("Exceptio2n thrown for classes generated by #import");
TRACE("\tCode=%08lx\n",e.Error());
TRACE("\tCode meaning=%s\n",e.ErrorMessage());
TRACE("\tSource=%s\n",(LPCTSTR)bstrSource);
TRACE("\tDesption=%s\n",(LPCTSTR)bstrDescription);
}
catch(...)
{
TRACE("***Unhandled Exception***");
}
欢迎來到Java学习者论壇,zhuan载请注明地址:http://www.javaxxz.com. |
|