怎么在MFC中用List Control实现数据库的增删改?
1个回答
2013-07-12
展开全部
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();
}
}
{
// 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();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询