VC中的几个小问题,谢谢
函数查找数据库中的数据时,经常碰到这几句,求专家帮菜鸟逐句注释下,感谢!
//AfxOleInit();
m_pConnection.CreateInstance(__uuidof(Connection));
TCHAR tstrCurrentPath[MAX_PATH];
//initialize
memset(tstrCurrentPath, 0, MAX_PATH);
//Get
GetCurrentDirectory(MAX_PATH, tstrCurrentPath);
CString strPath;
strPath.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s\\数据库.mdb", tstrCurrentPath);
try
{
m_pConnection->Open(strPath.GetBuffer(strPath.GetLength()),"","",adModeUnknown);
} catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库是否在当前路径下!");
return false;// ;
}
CString temp;
temp.Format("SELECT * FROM 课表");
BSTR temp1=temp.AllocSysString();
_RecordsetPtr pRecordset_power;
pRecordset_power.CreateInstance(__uuidof(Recordset));
try
{
pRecordset_power->Open(temp1,
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
} catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return false;
}