MFC对话框如何连接Access数据库的数据

网络整理 - 07-27

  解决方案:

  try

  {

  hr = m_pConnection.CreateInstance("ADODB.Connection");///

  if( TRUE == SUCCEEDED(hr))

  {

  strDBFile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDBFile;

  hr = m_pConnection->Open((_bstr_t)strDBFile ,_bstr_t(strUser),_bstr_t(strUser),adModeUnknown);

  }

  }

  catch(_com_error e)

  {

  CString errormessage;

  errormessage.Format("%s",e.ErrorMessage());

  AfxMessageBox(errormessage);

  return FALSE;

  }