void CExec4Dlg::OnButton1() 
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_sname == "" || m_sno == "")
{
AfxMessageBox("学号和姓名信息不能为空!");
return;
}

try
{

m_pRecordset->AddNew(); 
                  m_pRecordset->PutCollect("sno", _variant_t(m_sno));
     m_pRecordset->PutCollect("sname", _variant_t(m_sname));
m_pRecordset->PutCollect("age", _variant_t(m_age));
m_pRecordset->PutCollect("dept", _variant_t(m_dept));
     m_pRecordset->PutCollect("comment", _variant_t(m_comment));
m_pRecordset->Update();
UpdateData(false);
AfxMessageBox("插入成功!");

int nCurSel = m_list.GetCurSel();
List(); // m_list.SetCurSel(nCurSel);

OnSelchangeList1(); }
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}

}、
MFC 函数添加记录到数据库时候执行 至红色的代码发生了runtime错误,!!数据库是联通了,而且可以在列表框里显示和查找数据库的内容,就是插入和修改记录这两个功能一执行就会发生runtime错误。求大神帮忙分析下是什么原因,本人菜鸟刚学的。

解决方案 »

  1.   

    这里有解决方案:
    http://topic.csdn.net/t/20060709/10/4868751.html
      

  2.   

    参照这样写,看是否能插入进去,第二个字段如果是数字,要类型转换一下m_pRecordset->PutCollect("sno",_variant_t((long)m_sno))
      

  3.   

    m_pRecordset->close();//这个应该能刷新你的记录。
    不过,我觉得应该有个类似Commit的函数
      

  4.   

    m_pRecordset->Update()就类似于commit
      

  5.   


    是字符型的,改了以后编译报错。后来我用了insert 语句直接插 倒是可以成功了。改了两天了,不知道这是什么原因额 ?求大神指点。
      

  6.   

    确实比较诡异...
    那就直接用sql语句吧...方便,省事...