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)这里不行,好像是他们的长度不一样吧,咋写?求指教!
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)这里不行,好像是他们的长度不一样吧,咋写?求指教!
password1=atoi((LPCSTR)(_bstr_t)pRst1->GetCollect("pass"));//字符串
GetDlgItem(IDC_EDIT1)->GetWindowText(password0);字符串和INT这样是不能直接比较的。而且你也是找用户名和密码,不需要遍历记录集,只需要确认记录是否存在即可。
password1=atoi((LPCSTR)(_bstr_t)pRst1->GetCollect("pass"));//字符串
GetDlgItem(IDC_EDIT1)->GetWindowText(password0);字符串和INT这样是不能直接比较的。而且你也是找用户名和密码,不需要遍历记录集,只需要确认记录是否存在即可。