ADO MFC添加和修改的疑惑
一人在外 2012-08-28 11:13:14 void CINHADlg::OnBnClickedButton1() //添加
{
// TODO: 在此添加控件通知处理程序代码
CString str;
try
{
theApp.pRst->Close(); //在此处出错,前面打开过pRst。
theApp.pRst->Open("select * from EmInfo",theApp.pConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
theApp.pRst->AddNew();
FieldsPtr fieldsPtr;
fieldsPtr=theApp.pRst->Fields;
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
fieldsPtr->Item["EmNu"]->Value=(_bstr_t)str;
theApp.pRst->Update();
MessageBox("添加成功");
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
}
void CINHADlg::OnBnClickedButton3() //修改人员信息函数
{
CString str,sql;
try
{
theApp.pRst->Close();
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
sql.Format(_T("select * from EmInfo where EmNu = '%s'"),str);
theApp.pRst->Open((LPCSTR)sql,theApp.pConn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
FieldsPtr fieldsPtr;
fieldsPtr=theApp.pRst->Fields;
GetDlgItem(IDC_EDIT1)->GetWindowText(str);
fieldsPtr->Item["EmNu"]->Value=(_bstr_t)str;
theApp.pRst->Update();
MessageBox("添加成功");
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}*/
}
以上两个函数有错误,求大神鉴定错在何处。