在以下代码中
void CSellingDlg::OnKillfocusEDITProdCode() 
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_strProdCode=="") return;   //对应该CEdit
//    CSellingDlg::OnButton1();
     CString str;       
str="select * from Prod_Stocks where ProdCode='";
str+=m_strProdCode;
str+="'";
m_flag=true;
try
{
if(pRS->State) pRS->Close();
pRS->Open(str.AllocSysString(),
theApp.m_pConnect.GetInterfacePtr(),
adOpenStatic,adLockOptimistic,adCmdText);
if(pRS->adoEOF)
{
AfxMessageBox("并无此商品!");
m_ProdCode.SetFocus();
m_flag=false;
return;
}
i++;
m_flag=true;
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
catch(...)
{
AfxMessageBox("打开数据集错误!");
return;
}
}
运行后出现“打开数据集错误!”,但是把数据库查询语句放到其他出却没错!;
为什么?

解决方案 »

  1.   

    if(pRS->State) pRS->Close();改为
    pRS->State & adStateOpenstr.AllocSysString();没有释放,有Memory leak
      

  2.   

    把这两行注释掉则没问题?
    AfxMessageBox("并无此商品!");
    m_ProdCode.SetFocus();    //m_ProdCode为该控件的控件变量
      

  3.   

    该段代码放到其他事件中无问题如OnButton1();
    不知这是为何?急!急!急!分不够可以加
      

  4.   

    ResIf an application is displaying a caret, the caret should be destroyed at this point. While processing this message, do not make any function calls that display or activate a window. This causes the thread to yield control and can cause the application to stop responding to messages. For more information, see Message Deadlocks. 知道原因了吧,不能在WM_KILLFOCUS里再设置 SetFocus
      

  5.   

    该问题昨天已发现,那为什么这行AfxMessageBox("并无此商品!");也要注释掉