帮忙看一下这个基于MFC的对话框编程的一部分代码
void CFdasfDlg::OnButton1() {
// TODO: Add your control notification handler code here
CString str;
m_Dep.GetLBText(m_Dep.GetCurSel(),str);
ADOConn m_ADOConn;
m_ADOConn.OnInitADOConn();
CString sql;
sql.Format("select * from tb_phonebook where 所在部门 = '%s'",str);
m_ADOConn.m_pRecordset = m_ADOConn.GetRecordSet((_bstr_t)sql);
while(!m_ADOConn.m_pRecordset->adoEOF)
{
m_ID[m_Num] = (char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("编号");
m_Name[m_Num] = (char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("姓名");
m_Phone[m_Num] = (char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("电话号码");
m_ADOConn.m_pRecordset->MoveNext();
m_Num++;
}
i=0;
while(m_Num>=i)
{
UpdateData(TRUE);
CString sql;
sql.Format("insert into tb_abc(bianhao,xingming,dianhua) values ('%s','%s','%s')",m_ID[i],m_Name[i],m_Phone[i]);
m_ADOConn.ExecuteSQL((_bstr_t)sql);
i++;
}
sql.Format("select * from tb_abc");
m_ADOConn.m_pRecordset = m_ADOConn.GetRecordSet((_bstr_t)sql);
ababababab bb;
bb.m_Grid.InsertItem(i,"");
while(!m_ADOConn.m_pRecordset->adoEOF)
{bb.m_Grid.InsertItem(i,"");
bb.m_Grid.SetItemText(i,0,(char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("bianhao"));
bb.m_Grid.SetItemText(i,1,(char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("xingming"));
bb.m_Grid.SetItemText(i,2,(char*)(_bstr_t)m_ADOConn.m_pRecordset->GetCollect("dianhua"));
m_ADOConn.m_pRecordset->MoveNext();
m_ADOConn.ExitConnect();
CDialog::OnCancel();
}
void CFdasfDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_Num = 1;
int pos = m_Gri.GetSelectionMark();
m_ID[0] = m_Gri.GetItemText(pos,0);
m_Name[0] = m_Gri.GetItemText(pos,1);
m_Phone[0] = m_Gri.GetItemText(pos,5);
UpdateData(TRUE);
ADOConn m_ADOConn;
m_ADOConn.OnInitADOConn();
CString sql;
sql.Format("insert into tb_abc(bianhao,xingming,dianhua) values ('%s','%s','%s')",m_ID[0],m_Name[0],m_Phone[0]);
m_ADOConn.ExecuteSQL((_bstr_t)sql);
ababababab aa ;
aa.m_Grid.InsertItem(0,"");
aa.m_Grid.SetItemText(0,0,m_ID[0]);
aa.m_Grid.SetItemText(0,1,m_Name[0]);
aa.m_Grid.SetItemText(0,2,m_Phone[0]);
}