保存到表中:
UpdateData(true); if(m_name.IsEmpty()) { MessageBox("姓名不能为空。","提示",MB_ICONINFORMATION); return; }else if(m_contact_name.IsEmpty()) { MessageBox("联系人姓名不能为空。","提示",MB_ICONINFORMATION); return; } CString sex,marriage; m_sex.GetLBText(m_sex.GetCurSel(),sex); m_marriage.GetLBText(m_marriage.GetCurSel(),marriage); CString complaints; m_richEdit.GetWindowText(complaints); CString m_admidate,m_using_date; SYSTEMTIME admiTm,useTm; memset(&admiTm,0,sizeof(SYSTEMTIME)); memset(&useTm,0,sizeof(SYSTEMTIME)); ((CDateTimeCtrl*)GetDlgItem(IDC_ADMIDATE))->GetTime(&admiTm); ((CDateTimeCtrl*)GetDlgItem(IDC_USINGDATE))->GetTime(&useTm); m_admidate.Format("%d-%d-%d",admiTm.wYear,admiTm.wMonth,admiTm.wDay); m_using_date.Format("%d-%d-%d",useTm.wYear,useTm.wMonth,useTm.wDay); CString query="insert into PatientInfo values(NULL,'"+m_name+"','"+sex+"','"+m_age+"','"+m_her+"','"+m_position+"','"+marriage+"','"+m_nation+"','"+m_admidate+"','"+m_address+"','"+m_postcode+"','"+m_using_date+"','"+m_contact_name+"','"+m_relation+"','"+m_narrator+"','"+m_contact_addr+"','"+m_contact_tel+"','"+m_reliability+"','"+complaints+"');";
查询:
CListCtrl &m_list = GetListCtrl(); m_list.DeleteAllItems(); try{ CppSQLite3DB db; CppSQLite3Query query; CString str=""; CString name; name=GetPath(); db.open(name); query=db.execQuery(strSQL); int col=0; while(!query.eof()) { m_list.InsertItem(col,""); m_list.SetItemText(col,0,query.getStringField(0)); m_list.SetItemText(col,1,query.getStringField(1)); m_list.SetItemText(col,2,query.getStringField(2)); m_list.SetItemText(col,3,query.getStringField(4)); m_list.SetItemText(col,4,query.getStringField(8)); m_list.SetItemText(col,5,query.getStringField(9)); m_list.SetItemText(col,6,query.getStringField(11)); m_list.SetItemText(col,7,query.getStringField(12)); m_list.SetItemText(col,8,query.getStringField(13)); m_list.SetItemText(col,9,query.getStringField(15)); m_list.SetItemText(col,10,query.getStringField(16)); query.nextRow(); } } catch(CppSQLite3Exception& e) { const char* errormessage=e.errorMessage(); AfxMessageBox(errormessage); } } int CHPMANView::OnCreate(LPCREATESTRUCT lpCreateStruct) { lpCreateStruct->style |= LVS_REPORT | LVS_SHOWSELALWAYS; if (CListView::OnCreate(lpCreateStruct) == -1) return -1;
更新:
CString sex,marriage; m_sex.GetLBText(m_sex.GetCurSel(),sex); m_marriage.GetLBText(m_marriage.GetCurSel(),marriage); CString complaints; m_richEdit.GetWindowText(complaints); CString m_admidate,m_using_date; GetDlgItem(IDC_ADMIDATE)->GetWindowText(m_admidate); GetDlgItem(IDC_USINGDATE)->GetWindowText(m_using_date); CString query="Update PatientInfo set pname='"+m_name+"',sex='"+sex+"' ,age='"+m_age+"',her='"+m_her+"' ,position='"+m_position+"',marriage='"+marriage+"',nation='"+m_nation+"',admi_data='"+m_admidate+"' ,address='"+m_address+"' , postcode= '"+m_postcode+"',using_date= '"+m_using_date+"',contact_name='"+m_contact_name+"' ,relation= '"+m_relation+"',narrator='"+m_narrator+"' ,contact_addr='"+m_contact_addr+"' ,contact_tel='"+m_contact_tel+"' ,reliability='"+m_reliability+"' ,complaints='"+complaints+"' where id='"+id+"';";