在登陆对话框中使用_RecordsetPtr和 _ConnectionPtr没有出现异常
可是在添加图书中使用却出现异常,两者的代码几乎是完全一样的除了sql外。
请问这是为什么??

解决方案 »

  1.   

    可以呀
    在登陆空中访问用户名表是这样:
    CString str;
    str="select * from Mg where 用户名='"+m_user+"' and ";
    str=str+"密码='"+m_pass+"'";

    CPJApp *theApp=(CPJApp *)AfxGetApp();

    theApp->pRecordset=theApp->pConnection->Execute((_bstr_t)str,NULL,adCmdText);
    这没有什么问题  但不调试也可以
    在图书表中点击添加图书按钮是这样:
    CString str;
    str="select * from Reader where 图书编号='"+m_booknumber+"'";

    CPJApp *theApp=(CPJApp *)AfxGetApp();
    theApp->pRecordset=theApp->pConnection->Execute((_bstr_t)str,NULL,adCmdText);//检查图示编号是否存在
    当再次执行时不能了    产生异常
      

  2.   

    产生的异常是IDispatch #error对话框
      

  3.   

    你的sql有问题,sql.Format=("select * from Mg where 用户名='%s' and 密码='%s',m_user,m_pass");
      

  4.   

    你的sql有问题,sql.Format=("select * from Mg where 用户名='%s' and 密码='%s'",m_user,m_pass); 用这个,或者用[]将变量名括起来也行
      

  5.   

    兄弟str语句完全正确!!!