我的数据表里面有两个字段 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; 虽然不报错了 但是不能正常运行

解决方案 »

  1.   

    你的Name变量的确没定义类型啊
      

  2.   

    Name是数据库里面一个字段名啊  
      

  3.   

    Name = m_strLoginName; 
    这里的Name你定义了吗?
      

  4.   

    系统怎么会知道Name是数据库里面一个字段名呢
      

  5.   

    定义下你的Name,CString Name,把数据库中取出来的值赋给Name就可以了。
      

  6.   

    在什么地方定义啊 Dlg类里还是App里 怎么获取数据库里取出的值啊 能不能给一下具体的代码
      

  7.   


    要把用户名写到数据库是需要运行SQL语句的m_strLoginName
    另外 OnOK(); 要放在最后写,因为OnOK(); 登陆程序就退出了,当然不会执行后面的了
    else 

    Name = m_strLoginName; 
    ::Sleep(300); CMainDlg dlg; 
    dlg.DoModal(); 
    OnOK(); 
      

  8.   


    //如://你的对话框类中,两个编辑框一个是输入用户名的,一个是输入密码的.
    //在你的对话框类的头文件里面定义
    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("用户名或者密码错误!");
    }