代码如下,运行到m_pRecordset->Open时报错,Runtime error!
请大虾指点 CString strSql="select * from user where id=";
CString strId; m_user.GetWindowText(strId);
strSql=strSql+strId; BSTR bstrSQL = strSql.AllocSysString(); 
m_pRecordset->Open(bstrSQL,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if (m_pRecordset->adoEOF && m_pRecordset->BOF)
{
if (MessageBox("没有此用户,您要重新输入吗?!","提示",MB_YESNO)==IDYES)
{
m_user.SetWindowText(NULL);
m_user.SetFocus();
}
}

解决方案 »

  1.   

    在窗口初始化时都已经打开了,都是正常的阿
    CoInitialize(NULL); try
    {
    hr=m_pConnection.CreateInstance(__uuidof(Connection));
    hr=m_pRecordset.CreateInstance(__uuidof(Recordset));
    if (SUCCEEDED(hr))
    {
    hr=m_pConnection->Open("Driver={SQL Server};Server=DEVELOP2;DATABASE=rms","","",0);
    }
    }
    catch(_com_error e)
    {
    AfxMessageBox(e.ErrorMessage());
    }
      

  2.   

    CString strSql="select * from [user] where [id]=";
      

  3.   

    id是数据库的保留关键字。
    user是一个函数名。
    系统无法分辨他是字段还是函数或其他。所以加上[]指示为字段
    最好不要用这两个作字段名。