MFC ADO连接数据库 删除记录时出错
voidCCTESTDlg::Ondelete(){//TODO:AddyourcontrolnotificationhandlercodeherePOSITIONpos...
void CCTESTDlg::Ondelete() { // TODO: Add your control notification handler code here POSITION pos = m_list.GetFirstSelectedItemPosition(); int nItem; if ( NULL == pos ) { TRACE0("No items were selected!\n"); } else { while (pos) { nItem = m_list.GetNextSelectedItem(pos); } } CString cName=m_list.GetItemText(nItem,0);
CAdo ado; ado.OnInitAdoConn(); _RecordsetPtr pRecordset=ado.GetReordset(); pRecordset=ado.OpenRecordset("select * from 表1");
CString sql="select * from 表1 where 姓名 = '"+cName+"'"; pRecordset=ado.OpenRecordset(sql);
pRecordset->Delete(adAffectCurrent); pRecordset->Update (); MessageBox("删除成功"); ado.ExitConnection(); m_list.DeleteItem(nItem); }
点击删除按钮以后出现下面这个
void CAdo::ExitConnection(){ if(m_pRecordset->GetState() == adStateOpen) { m_pRecordset->Close(); m_pRecordset = NULL; }
if(m_pConnection->State) { m_pConnection->Close(); m_pConnection = NULL; }
} 展开
CAdo ado; ado.OnInitAdoConn(); _RecordsetPtr pRecordset=ado.GetReordset(); pRecordset=ado.OpenRecordset("select * from 表1");
CString sql="select * from 表1 where 姓名 = '"+cName+"'"; pRecordset=ado.OpenRecordset(sql);
pRecordset->Delete(adAffectCurrent); pRecordset->Update (); MessageBox("删除成功"); ado.ExitConnection(); m_list.DeleteItem(nItem); }
点击删除按钮以后出现下面这个
void CAdo::ExitConnection(){ if(m_pRecordset->GetState() == adStateOpen) { m_pRecordset->Close(); m_pRecordset = NULL; }
if(m_pConnection->State) { m_pConnection->Close(); m_pConnection = NULL; }
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询