我的数据表里面有两个字段 Name 和 Age
代码如下:
void CConnecttDlg::OnBtnOk()
{
// TODO: Add your control notification handler code here
CString strsql;
_variant_t strQuery;
UpdateData(TRUE); if(m_strLoginName.IsEmpty())
{
AfxMessageBox("请输入用户名:");
return ;
}
strQuery="SELECT * FROM table WHERE Name='"+m_strLoginName+"'AND Age='"+m_strPasswd+"'";
theApp.ADOExecute(theApp.m_pRs,strQuery);
int iCount = theApp.m_pRs->GetRecordCount();
if(0 == iCount)
{
AfxMessageBox("用户名错误");
m_strLoginName="";
m_strPasswd="";
UpdateData(false); }
else
{
Name = m_strLoginName;
::Sleep(300);
OnOK();
CMainDlg dlg;
dlg.DoModal();
}
}void CConnecttDlg::OnBtnCal()
{
// TODO: Add your control notification handler code here
OnCancel();
}
报错是0\MSDev98\MyProjects\connectt\connecttDlg.cpp(202) : error C2065: 'Name' : undeclared identifier
D:\My Documents\VC6.0\MSDev98\MyProjects\connectt\connecttDlg.cpp(202) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
Error executing cl.exe.
大家帮我看一下怎么改 谢谢了啊 去掉Name = m_strLoginName; 虽然不报错了 但是不能正常运行
代码如下:
void CConnecttDlg::OnBtnOk()
{
// TODO: Add your control notification handler code here
CString strsql;
_variant_t strQuery;
UpdateData(TRUE); if(m_strLoginName.IsEmpty())
{
AfxMessageBox("请输入用户名:");
return ;
}
strQuery="SELECT * FROM table WHERE Name='"+m_strLoginName+"'AND Age='"+m_strPasswd+"'";
theApp.ADOExecute(theApp.m_pRs,strQuery);
int iCount = theApp.m_pRs->GetRecordCount();
if(0 == iCount)
{
AfxMessageBox("用户名错误");
m_strLoginName="";
m_strPasswd="";
UpdateData(false); }
else
{
Name = m_strLoginName;
::Sleep(300);
OnOK();
CMainDlg dlg;
dlg.DoModal();
}
}void CConnecttDlg::OnBtnCal()
{
// TODO: Add your control notification handler code here
OnCancel();
}
报错是0\MSDev98\MyProjects\connectt\connecttDlg.cpp(202) : error C2065: 'Name' : undeclared identifier
D:\My Documents\VC6.0\MSDev98\MyProjects\connectt\connecttDlg.cpp(202) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
Error executing cl.exe.
大家帮我看一下怎么改 谢谢了啊 去掉Name = m_strLoginName; 虽然不报错了 但是不能正常运行
这里的Name你定义了吗?
要把用户名写到数据库是需要运行SQL语句的m_strLoginName
另外 OnOK(); 要放在最后写,因为OnOK(); 登陆程序就退出了,当然不会执行后面的了
else
{
Name = m_strLoginName;
::Sleep(300); CMainDlg dlg;
dlg.DoModal();
OnOK();
}
//如://你的对话框类中,两个编辑框一个是输入用户名的,一个是输入密码的.
//在你的对话框类的头文件里面定义
CString strUserName,strPassword;GetDlgItem(IDC_EDIT_UserName)->GetWindowText(strUserName);
GetDlgItem(IDC_EDIT_Password)->GetWindowText(strPassword);//这两个变量是用来保存你从数据库中取出来的用户名和密码的。
//在你的对话框类的头文件里面定义
CString strDataUserName,strDataPassword;if((strUserName == strDataUserName) && (strPassword == strDataPassword))
{
//意思就是说当你的输入的用户名和密码与数据库中的用户名和密码都相等的时候
//在这里就做你要做的事情,大概就是你说的弹出对话框吧
}
else
{
MessageBox("用户名或者密码错误!");
}