首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

连sql sever 2000执行SQL语句有关问题

2012-01-15 
连sql sever 2000执行SQL语句问题请大家帮我看一下这几句代码那里出错了,看了一下午,郁闷死了现在的目的是

连sql sever 2000执行SQL语句问题
请大家帮我看一下这几句代码那里出错了,看了一下午,郁闷死了

现在的目的是查询表UserInfo,生成的select语句在查询分析器里可以执行,在vc   里却不行

void   CUserLoginDlg::OnOK()  
{
//   TODO:   Add   extra   validation   here
this-> UpdateData(TRUE);

//   不区分大小写
this-> m_userID.MakeUpper();
this-> m_userPwd.MakeUpper();

CStringstrSRC;

//strSRC= "select   userID,userName,userPwd,workingKey,deadLineDate   from   UserInfo   where   userID   = "   +   m_userID;        

        strSRC= "select   *   from   UserInfo   where   userID   = "   +   m_userID;        

_bstr_t   bcnstr(strSRC);
_RecordsetPtr   m_pRec;
_variant_t   RecordsAffected;
m_pConnection.CreateInstance(__uuidof(Connection));
//m_pRec.CreateInstance(__uuidof(Recordset));

try{

//执行
//   到这一步就直接跳出去了:(!!!!!!!!!!
m_pRec   =   m_pConnection-> Execute(   (   _bstr_t   )bcnstr   ,   &RecordsAffected   ,   adCmdText   );


if(   m_pRec-> BOF   )
{
MessageBox(   "用户名或密码错误记录集为空 "   );
return;
}


                m_pRec-> MoveFirst();

                //获得字段的值
                _variant_t   ouserID           =   m_pRec-> GetCollect   ( "userID ");
                _variant_t   ouserName     =   m_pRec-> GetCollect   ( "userName ");//用户登录账号
                _variant_t   ouserPwd           =   m_pRec-> GetCollect   ( "userPwd ");
                _variant_t   oworkingKey             =   m_pRec-> GetCollect   ( "workingKey ");
                _variant_t   odeadLineDate   =   m_pRec-> GetCollect   ( "deadLineDate ");
                m_pRec-> Close();

CString   strUserPwd   =   ouserPwd.bstrVal;


  //然后再比较密码对不对
                if(   strUserPwd   ==   m_userPwd   )
                {
                        //如果密码正确,设置
                        m_bLoginOK   =   TRUE;
MessageBox(   "密码正确,登录成功! "   );
CDialog::OnOK();                                                                 //用户密码正确,关闭对话框
                }
                else
                {
                          m_bLoginOK   =   FALSE;


                        MessageBox(   "用户名或密码错误! "   );
return;
                }
        }catch(   ...   ){
MessageBox(   "用户名或密码错误! "   );
return;
        }

}


在线等。。。。

[解决办法]
在其他地方调用过CoInitialize(NULL)没有,若没有,在try之前调用一次.

热点排行