📄 ado访问数据库.txt
字号:
ADO访问数据库
_RecordsetPtr m_pRecordset;
m_pRecordset=NULL;
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString m_strCmdText = _T("select * from WeatherModelForecast where DateTime='"+m_CurrentDate+"'" );
//在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
//因为它有时会经常出现一些想不到的错误
int tt=0;
try
{
m_pRecordset->Open((LPCTSTR)m_strCmdText, (LPCTSTR)m_strConnection, adOpenDynamic, adLockReadOnly, adCmdUnknown);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return "";
}
try
{
if(!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
COleVariant FldName;
FldName.vt=VT_BSTR;
FldName="Day01“;
tt= m_pRecordset->GetCollect((_variant_t)FldName).lVal;
// m_pRecordset->MoveLast();
}
else
{
m_pRecordset->Close();
m_pRecordset=NULL;
return "";
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
m_pRecordset->Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -