void CStuInfoModify::OnOK()
{
RecordsetPtr pRs = NULL;
_ConnectionPtr pConnection = NULL;
_bstr_t strCnn(SQLCONSTR);
try
{
UpdateData(TRUE);
// 打开连接
pConnection.CreateInstance(_uuidof(Connection));
pConnection->Open(strCnn,"","",NULL);
pRs.CreateInstance(__uuidof(Recordset));
// 根据学号查询学生信息
CString SqlStr;
SqlStr.Format("select 备注 from xs where 学号 = '%s'",m_StuXH);
pRs->Open(_variant_t(SqlStr),_variant_t((IDispatch *) pConnection,FALSE),adOpenDynamic,adLockOptimistic,adCmdText);
if(!pRs->adoEOF)
{
pRs->PutCollect("备注", _variant_t(m_StuBZ));
pRs->Update(); // 更新到数据库
}
pRs->Close();
pConnection->Close();
m_StuADO.Refresh();
m_StuDG.ReBind();
m_StuDG.Refresh();
AfxMessageBox("更新成功!");
}
catch(_com_error &e)
{
// 捕捉异常
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// 格式化错误提示字符串
CString sError;
sError.Format("Source:%sDescription:%s",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
// 弹出错误对话框
AfxMessageBox(sError);
}
//CDialog::OnOK();
}