我现在是准备做一个登录界面,用户名称和密码都保存在数据库中。
CString logIn="select acc_user,acc_passwd from accounts where acc_user = '"+m_edit_userName+"' and acc_passwd = '"+m_edit_passWord+"'";
m_adodc_logIn.SetRecordSource(logIn);
m_adodc_logIn.Refresh();
//然后我不知道该怎样判断是否查找成功,后来想定义了一个DataGrid,数据源指向
//m_adodcsd_logIn,通过判断DataGrid是否为空来判断是否成功查找到用户。
if(){ //这里我试过m_datagrid_logIn.GetDlgItem(0)!=NULL
MessageBox(_T("登录成功!"));
}
else{
MessageBox(_T("登录失败!"));
}
但是这样判断不可以。请教各位大牛该怎么设计。求指点。
你查找出来是个字符串,完后判断两个字符串是否相等就好了啊
http://download.csdn.net/detail/wangyaninglm/3172109
我之前也是用ado连的,你试试看里面代码
void Cboard::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
_variant_t var;
CString strtext;
UpdateData(TRUE);
try
{
CString sql;
sql.Format(_T("select * from password where name='%s' and password='%s' " ),m_name,m_password);
_RecordsetPtr p_Recordset;
p_Recordset.CreateInstance(__uuidof(Recordset));
p_Recordset->CursorLocation=adUseClient;
p_Recordset->Open((_bstr_t)sql,p_Connection5.GetInterfacePtr(),adOpenStatic,
adLockOptimistic,adCmdUnknown);
while(!p_Recordset->adoEOF)
{
var = (_bstr_t)p_Recordset->GetCollect(_T("shenfen"));
strtext = (LPCSTR)_bstr_t(var);
if (p_Recordset->GetRecordCount()==1)
{
MessageBox("成功登录!");
strtext.TrimRight(_T(" "));
//MessageBox( "@" + strtext + "@");
if(strtext=="学生")
{
MessageBox("欢迎学生登录");
i=1;
}
if(strtext=="老师")
{
MessageBox("欢迎老师登录");
i=2;
}
if(strtext=="管理员")
{
MessageBox("欢迎管理员登录");
i=3;
}
break;
}
else
MessageBox("请输入正确的用户名和密码!");
p_Recordset->MoveNext();
}
}
catch(_com_error e)
{
AfxMessageBox(_T("Failed!本次登录出问题了。。。"));
}
}
我都不知道我写的是啥了,哈哈
好像不行,连接的语句、执行SQL的语句、获取的记录集语句到那里去?
刚开始学的,没想到用记录集,看了楼上的解决方法,正在试。
链接数据库本身是一种意义。