GetDlgItem(IDC_EDIT2)->GetWindowText(user0);
GetDlgItem(IDC_EDIT1)->GetWindowText(password0);
CoInitialize(NULL);//初始化
_ConnectionPtr pConn1(__uuidof(Connection));//产生connection智能指针
_RecordsetPtr pRst1(__uuidof(Recordset));//产生recordset智能指针
pConn1->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=图书管理系统";
pConn1->Open("","","",adConnectUnspecified);//打开数据库
char exstr[256];
sprintf(exstr, "select * from 登陆信息");
pRst1=pConn1->Execute(exstr,NULL,adCmdText);
        user1=(LPCSTR)(_bstr_t)pRst1->GetCollect("myuser");
password1=atoi((LPCSTR)(_bstr_t)pRst1->GetCollect("pass"));
while(!pRst1->rsEOF )
{   
if(user0==user1&&password0==password1)
{
MessageBox("登陆成功!");
break;
}
pRst1->MoveNext ();
}代码如上,问题是貌似if(user0==user1&&password0==password1)这里不行,好像是他们的长度不一样吧,咋写?求指教!

解决方案 »

  1.   

    本帖最后由 zyq5945 于 2011-12-05 12:30:37 编辑
      

  2.   

    pConn1->Open("","","",adConnectUnspecified);//打开数据库我觉得这句话有问题  adConnectUnspecified 改成 adModeUnknown试试
      

  3.   

    //int型变量
    password1=atoi((LPCSTR)(_bstr_t)pRst1->GetCollect("pass"));//字符串
    GetDlgItem(IDC_EDIT1)->GetWindowText(password0);字符串和INT这样是不能直接比较的。而且你也是找用户名和密码,不需要遍历记录集,只需要确认记录是否存在即可。
      

  4.   

    //int型变量
    password1=atoi((LPCSTR)(_bstr_t)pRst1->GetCollect("pass"));//字符串
    GetDlgItem(IDC_EDIT1)->GetWindowText(password0);字符串和INT这样是不能直接比较的。而且你也是找用户名和密码,不需要遍历记录集,只需要确认记录是否存在即可。