ado访问数据库.txt
来自「数据库系统:访问数据库。访问数据库并能对出错进行捕捉」· 文本 代码 · 共 48 行
TXT
48 行
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 + =
减小字号Ctrl + -
显示快捷键?