我的代码:
GetDlgItem(IDC_EDIT1)->GetWindowText(m_bt);
  CString str; 
  str.Format("insert into wz (title) values(%s)",m_bt); 
  m_pConnection->Execute((_bstr_t)str,NULL,adCmdText); 
现在已经可以把IDC_EDIT1控件里的数据写入数据库记录里了,可是我有好几个类似控件,要一起写入同一条记录里,这怎么弄?

解决方案 »

  1.   

    GetDlgItem(IDC_EDIT1)->GetWindowText(m_bt); 
    GetDlgItem(IDC_EDIT2)->GetWindowText(m_bt1); 
      CString str; 
      str.Format("insert into wz (title,xxx...) values(%s,%s...)",m_bt,m_bt1...); 
      m_pConnection->Execute((_bstr_t)str,NULL,adCmdText); 
      

  2.   

    那就用RecordSet,打开一个记录集后,用AddNew添加一个新记录,然后再用PutCollect往各字段里写值,最后再用Update更新,这样便保存成功。
      

  3.   

    这样编译没问题,运行出错。
    m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);这句调试完就出现显示unhandled exception in 0.exe 
    不知道问什么?是不是因为IDC_COMBO1
    CString strTemp;
    GetDlgItem(IDC_EDIT1)->GetWindowText(m_bt); 
    GetDlgItem(IDC_COMBO1)->GetWindowText(strTemp); 
      CString str; 
      str.Format("insert into wz (title,class) values(%s,%s)",m_bt,strTemp); 
      m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);
      

  4.   

    引用 1 楼 dirdirdir3 的回复:
    GetDlgItem(IDC_EDIT1)->GetWindowText(m_bt);
    GetDlgItem(IDC_EDIT2)->GetWindowText(m_bt1);
      CString str;
      str.Format("insert into wz (title,xxx...) values(%s,%s...)",m_bt,m_bt1...);
      m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);
    这样编译没问题,运行出错。
    m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);这句调试完就出现显示unhandled exception in 0.exe
    不知道问什么?是不是因为IDC_COMBO1
    CString strTemp;
    GetDlgItem(IDC_EDIT1)->GetWindowText(m_bt);
    GetDlgItem(IDC_COMBO1)->GetWindowText(strTemp);
      CString str;
      str.Format("insert into wz (title,class) values(%s,%s)",m_bt,strTemp);
      m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);
    [/Quote]
    str.Format("insert into wz (title,class) values(‘%s’,‘%s’)",m_bt,strTemp);
      m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);
      

  5.   

    我觉得问题可能还是出在这个控件上IDC_COMBO1,他是一个组合框,固定了几个值,我用别的IDC_EDIT1这个空间就没有问题
      

  6.   

    是不是对于组合框(只能从下拉列表里选值)不能用GetDlgItem(IDC_COMBO1)->GetWindowText(strTemp); 这个代码啊
      

  7.   

    CString   str; 
      m_combo.GetLBText(0,str); 
    我这么写了,结果编译错误error C2228: left of '.GetLBText' must have class/struct/union type
    Error executing cl.exe.
    可我已经定义了这个成员变量了啊