void CDATABASE_ADO_TESTDlg::OnButton4()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_strID==0||m_strName=="")
{
AfxMessageBox("编号和姓名两者都不能为空!");
return;
}
_RecordsetPtr pRS;
if(FAILED(pRS.CreateInstance("ADODB.Recordset")))
{
AfxMessageBox("Create Instance failed!");
return;
}
CString strSRC=GetConnStr();
CString strSQL;
strSQL.Format("select * from Student where StudentID=%d",m_strID);
if(FAILED(pRS->Open((_variant_t)strSQL,(_variant_t)strSRC,adOpenStatic,adLockOptimistic,adCmdText)))
{
AfxMessageBox("Can not open Database!");
pRS.Release();
return;
}
if(!pRS->GetrsEOF())
{
pRS->MoveLast();
}
pRS->AddNew();
pRS->PutCollect("Name",(_variant_t)m_strName);
pRS->PutCollect("Sex",(_variant_t)m_strSex);
pRS->PutCollect("Major",(_variant_t)m_strMajor);
pRS->PutCollect("StudentID",(_variant_t)(long)m_strID);
pRS->PutCollect("Age",(_variant_t)(long)m_iAge);
pRS->Update();
pRS.Release();
}
代码_ADO_增加记录
最新推荐文章于 2020-10-29 21:20:15 发布