void CDATABASE_ADO_TESTDlg::OnButton2()
{
// 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;
}
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();
}
注意:_variant_t并不存在int类型的转化,所以要加(long)