Title is No Title

not very good here!

导航

use CDatabase is simple,example is:

//add the selected guanqu info.
 //and reshow them.
    CEdit* ed=(CEdit*)GetDlgItem(IDC_CODE);
 CString edc;
 ed->GetWindowText(edc);
 CString guanQvNO=edc;
 //name
    ed=(CEdit*)GetDlgItem(IDC_NAME);
    ed->GetWindowText(edc);
 CString guanQvName=edc;
 //qi:
 ed=(CEdit*)GetDlgItem(IDC_qi);
    ed->GetWindowText(edc);
 CString guanQvQi=edc;
    //zhi
 ed=(CEdit*)GetDlgItem(IDC_zhi);
    ed->GetWindowText(edc);
 CString guanQvZhi=edc;
 //pinYin
 ed=(CEdit*)GetDlgItem(IDC_pinYin);
    ed->GetWindowText(edc);
 CString guanQvPinYin=edc;
 
 //beiZhu
 ed=(CEdit*)GetDlgItem(IDC_BeiZhu);
    ed->GetWindowText(edc);
 CString guanQvBeiZhu=edc;

 if(guanQvNO.Compare("")==0||guanQvName.Compare("")==0){
 AfxMessageBox("¹ÜÇøÃû³ÆºÍ´úÂë²»ÄÜΪ¿Õ!");
 return;
 }
CString insertSql;
insertSql.Format("insert into Info_¹ÜÇø values('%s','%s','%s','%s','%s','%s')",guanQvNO,guanQvName,guanQvQi,guanQvZhi,guanQvPinYin,guanQvBeiZhu);

    CDatabase db;
 int ret=AfxMessageBox("È·¶¨Ìí¼ÓÂð?",IDOK||IDNO);
    if(ret==IDOK){
 try{
     CString strConn;
  strConn.Format("ODBC;DSN=JiSheng;UID=;PWD=");
  if(!db.Open(NULL,FALSE,FALSE,strConn,TRUE))
  MessageBox("can not open db","info",MB_OK);
  db.ExecuteSQL(insertSql);
  //db.ExecuteSQL("");
  db.Close();
 

 }catch(CDBException e){
  e.ReportError();
 
 }
 AfxMessageBox("Ìí¼Ó¹ÜÇø³É¹¦!");
 //call to refresh!
    refresh();
 }
 
}

posted on 2004-03-27 17:58  abraham  阅读(819)  评论(0)    收藏  举报