void CSjtestDlg::OnBnClickedButtonDelete() { // TODO: 在此添加控件通知处理程序代码 int indx = m_Grid.GetSelectionMark() ; //选中序号 CString str = m_Grid.GetItemText(indx,1) ; if (indx < 0) return ; CString info ; for ( int i = 0 ; i < 4 ; i++){ info += m_Grid.GetItemText(indx,i) ; info += _T( "\n" ) ; } if (AfxMessageBox(info,MB_OKCANCEL,MB_ICONQUESTION) != IDOK) return ; ADOConn m_adoconn ; m_adoconn.OnInitADOConn() ; CString sql ; sql.Format(_T( "Delete from employees where 员工姓名 = '%s' " ),str) ; m_adoconn.ExecuteSQL((_bstr_t)sql) ; m_Grid.DeleteAllItems() ; sql.Format(_T( "select * from employees order by 员工编号 desc" )) ; m_adoconn.m_pRecordset = m_adoconn.GetRecordSet((_bstr_t)sql) ; while (! m_adoconn.m_pRecordset->adoEOF) { m_Grid.InsertItem(0,_T( "" )); m_Grid.SetItemText(0,0,(_bstr_t)m_adoconn.m_pRecordset->GetCollect(_T( "员工编号" ))); m_Grid.SetItemText(0,1,(_bstr_t)m_adoconn.m_pRecordset->GetCollect(_T( "员工姓名" ))); m_Grid.SetItemText(0,2,(_bstr_t)m_adoconn.m_pRecordset->GetCollect(_T( "所属部门" ))); m_Grid.SetItemText(0,3,(_bstr_t)m_adoconn.m_pRecordset->GetCollect(_T( "基本工资" ))); //将记录集指针移动到下一条记录 m_adoconn.m_pRecordset->MoveNext(); } m_adoconn.ExitConnect() ; } |