如果是一口气判断就是: rs->Open("select * from tablename where name='username' and pass='password'",...); if (rs->BOF) { AfxMessageBox("无此用户或密码错误"); } 如果要分开来判断就是: rs->Open("select * from tablename where name='username'",...); if (rs->BOF) { AfxMessageBox("无此用户"); } else { CString temp; _variant_t var; var=rs->GetCollect("pass"); temp=(LPCSTR)_bstr_t(var); if (temp!=password) { AfxMessageBox("你输入的密码有误"); } }
TO : DebugXP() ( ) 信誉:117 你的这个句:if 输入的密码==rs("pass") 问问如果有两个人名字一样 那得到的 pass 因该是两个 你的 rs("pass") 是返那一个呢。。还问问: 恩: rs->Open("select [name] from bb where id = 1",...); id 唯一:怎么得到 这个name 并 复给 CString aa; 是不是 aa = rs.******
其实是问:rs->Open("select min(id) from bb ",...);怎么得到结果并副给 int a;
名字重复的话就把编号也加上,编号应该是唯一的。 ———————————————————————————————— rs->Open("select [name] from bb where id = 1",...);_variant_t var; CString aa; var=rs->GetCollect("name"); aa=var.bstrVal; ———————————————————————————————— rs->Open("select min(id) as minID from bb where id = 1",...);_variant_t var; int aa; var=rs->GetCollect("minID"); aa=var.intVal;
if rs->RecordCount()<=0
{
//用户不存在
Return flase;
}
else
{
if 输入的密码==rs("pass")
{
//登陆成功
Reutrn ture;
}
else
{
//密码错误
Return flase;
}
}
{
// TODO: Add extra validation here
UpdateData(TRUE);
CUserRecordSet m_userRecordSet;
try
{
if(m_userRecordSet.IsOpen())//判断pUser记录集是否打开,如果打开则关闭,以保证后面的操作正确执行
m_userRecordSet.Close();
m_userRecordSet.m_strFilter.Format("UserName = '%s' and UserPwd = '%s'",
m_strUserName,m_strUserPwd);
m_userRecordSet.Open(CRecordset::snapshot,NULL,CRecordset::none);//执行查询操作
//判断符合条件的记录集是否为空,如果为空表明用户名或者密码不正确,给出相应的警告。
//如果不为空,表明用户名和密码正确,给出相应的提示
if(m_userRecordSet.IsEOF())
{
m_userRecordSet.Close();
AfxMessageBox("密码错误,请重试!");
return;
}
else
{
m_userRecordSet.Close();//操作完成后关闭数据库
AfxMessageBox("密码正确,登录成功!");
}
}
catch(CDBException *e)
{
e->ReportError();//将错误报告到界面上
//e->Delete();//将错误删除
return;
}
CDialog::OnOK();
}
rs->Open("select * from tablename where name='username' and pass='password'",...);
if (rs->BOF)
{
AfxMessageBox("无此用户或密码错误");
}
如果要分开来判断就是:
rs->Open("select * from tablename where name='username'",...);
if (rs->BOF)
{
AfxMessageBox("无此用户");
}
else
{
CString temp;
_variant_t var;
var=rs->GetCollect("pass");
temp=(LPCSTR)_bstr_t(var);
if (temp!=password)
{
AfxMessageBox("你输入的密码有误");
}
}
问问如果有两个人名字一样 那得到的 pass 因该是两个
你的 rs("pass") 是返那一个呢。。还问问:
恩:
rs->Open("select [name] from bb where id = 1",...);
id 唯一:怎么得到 这个name 并 复给 CString aa;
是不是 aa = rs.******
————————————————————————————————
rs->Open("select [name] from bb where id = 1",...);_variant_t var;
CString aa;
var=rs->GetCollect("name");
aa=var.bstrVal;
————————————————————————————————
rs->Open("select min(id) as minID from bb where id = 1",...);_variant_t var;
int aa;
var=rs->GetCollect("minID");
aa=var.intVal;
DebugXP() ( ) 信誉:117