ado的登录判断问题?

shiter
人工智能领域优质创作者
博客专家认证
2010-11-24 09:49:11
ado连接数据库,登录,看看输入的密码等不等与数据库password中的password
代码如下:

int tag=0;
//CDialog::OnOK();
UpdateData(TRUE);
try
{


CString sql;
sql.Format(_T("select * from password"));

_RecordsetPtr p_Recordset;
p_Recordset.CreateInstance(__uuidof(Recordset));
p_Recordset->Open((_bstr_t)sql,p_Connection1.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdUnknown);


while(!p_Recordset->adoEOF)
{

if (m_passsword==(_bstr_t)p_Recordset->GetCollect((_T("password")))))//不知道这里写的对不?
{
MessageBox("成功登录!");
tag=1;
break;
}

p_Recordset->MoveNext();
}
if (tag==1)
{
dlg1.DoModal();//显示相应的学生数据库增加,删除信息对话框
}
else
MessageBox("请输入正确的用户名和密码!");

}
catch(_com_error e)
{
AfxMessageBox(_T("Failed!"));
}
大家有什么,好的办法,?
我还是不太了解p_Recordset->GetCollect的返回值是啥类型的?
我这个编译连接都没问题,但是就是说("请输入正确的用户名和密码!");
我估计就是if (m_passsword==(_bstr_t)p_Recordset->GetCollect((_T("password")))))这个判断不对。。。
...全文
80 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiter 2010-11-25
  • 打赏
  • 举报
回复
问题到底出在哪了呢?
shiter 2010-11-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 chenjelly 的回复:]
不用那么麻烦吧,你直接修改你的 select语句,然后判断打开的记录集中的记录个数是否>1就可以验证了
[/Quote]

CString sql;
sql.Format(_T("select * from password where name='%s' and password='%s'" ),m_name,m_passsword);

_RecordsetPtr p_Recordset;
p_Recordset.CreateInstance(__uuidof(Recordset));
p_Recordset->Open((_bstr_t)sql,p_Connection1.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdUnknown);


if (p_Recordset->GetRecordCount()==1)
{
MessageBox("成功登录!");
tag=1;
//break;
}
if (tag==1)
{
dlg1.DoModal();
}
else
MessageBox("请输入正确的用户名和密码!");

}
这么搞?没反应,直接跳到下一句去了,,
shiter 2010-11-25
  • 打赏
  • 举报
回复
转换过了,还是有问题,找不到记录好像。。。
Ionstorm2 2010-11-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wangyaninglm 的回复:]

引用 2 楼 free1985 的回复:
p_Recordset->GetCollect的返回值是_variant_t类型;

C/C++ code

_variant_t var;
CString str;
var =p_Recordset->GetCollect("password");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t……
[/Quote]

vt_null指的是某个记录的这个字段值为null,一般用于做判断的
chenjelly 2010-11-25
  • 打赏
  • 举报
回复
不用那么麻烦吧,你直接修改你的 select语句,然后判断打开的记录集中的记录个数是否>1就可以验证了
shiter 2010-11-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 free1985 的回复:]
p_Recordset->GetCollect的返回值是_variant_t类型;

C/C++ code

_variant_t var;
CString str;
var =p_Recordset->GetCollect("password");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);
[/Quote]
if(var.vt != VT_NULL)//请问这句,中,vt_null是啥意思??
李明子 2010-11-24
  • 打赏
  • 举报
回复
p_Recordset->GetCollect的返回值是_variant_t类型;

_variant_t var;
CString str;
var =p_Recordset->GetCollect("password");
if(var.vt != VT_NULL)
str = (LPCSTR)_bstr_t(var);

shiter 2010-11-24
  • 打赏
  • 举报
回复
自己顶个。。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧