怎么在MFC中用List Control实现数据库的增删改?
- 提问者网友:雾里闻花香
- 2021-04-13 14:18
- 五星知识达人网友:低音帝王
- 2021-04-13 15:47
void SearchDepartment::OnBnClickedDelete()
{
// TODO: 在此添加控件通知处理程序代码
if(m_list.GetItemCount() == 0)
{
AfxMessageBox(_T("还没有记录"));
return;
}
else if(m_list.GetSelectionMark() < 0 || m_list.GetSelectionMark() > m_list.GetItemCount())
{
AfxMessageBox(_T("请先选择记录"));
return;
}
CString temp;
tempStr2 = m_list.GetItemText(m_list.GetSelectionMark(),1);
m_list.DeleteItem(m_list.GetSelectionMark());
m_db.Open(_T("peopleDSN"));
m_rs2.m_pDatabase = &m_db;
m_rs2.Open();
m_rs2.MoveFirst();
while(!m_rs2.IsEOF()){
if(m_rs2.m_dname == tempStr2){
temp = m_rs2.m_dID;
m_rs2.Close();
m_db.Close();
break;
}
else
m_rs2.MoveNext();
}
m_db.Open(_T("peopleDSN"));
m_rs.m_pDatabase = &m_db;
m_rs.Open();
m_rs.MoveFirst();
while(!m_rs.IsEOF()){
if(m_rs.m_dID == temp){
m_rs.Delete();
}
else
m_rs.MoveNext();
}
m_rs.Close();
m_db.Close();
m_db.Open(_T("peopleDSN"));
m_rs2.m_pDatabase = &m_db;
m_rs2.Open();
m_rs2.MoveFirst();
while(!m_rs2.IsEOF()){
if(m_rs2.m_dname == tempStr2){
m_rs2.Delete();
m_rs2.MoveFirst();
m_rs2.Close();
m_db.Close();
return;
}
else
m_rs2.MoveNext();
}
}
- 1楼网友:神也偏爱
- 2021-04-13 16:43