4,011
社区成员
发帖
与我相关
我的任务
分享
CoInitialize(NULL);
try
{
HRESULT hr;
m_pConnection.CreateInstance("ADODB.Connection");
hr=m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Mydata.mdb","","",adModeUnknown);
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format(_T("连接数据库失败!\n错误信息:%s"),e.ErrorMessage());
AfxMessageBox(errormessage);
}
try //将数据写入数据库的数据表中。
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open("SELECT * FROM 测量过程",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
// 写入各字段值
m_pRecordset->MoveLast();
_variant_t theValue;
theValue=m_pRecordset->GetCollect("气温"); //获取气温
m_temper=(char*)_bstr_t(theValue);
theValue=m_pRecordset->GetCollect("气压"); //获取气压
m_pressure=(char*)_bstr_t(theValue);
theValue=m_pRecordset->GetCollect("湿度"); //获取湿度
m_humidity=(char*)_bstr_t(theValue);
theValue=m_pRecordset->GetCollect("备注"); //获取备注
}
catch (_com_error e) // 显示错误信息
{
CString errormessage;
errormessage.Format(_T("更新记录失败!\r\n错误信息:%s", e.ErrorMessage()));
AfxMessageBox(errormessage);
}