每次程序运行到输入用户名和密码然后点确定的时候就会出现中断,查了相关内容说可能是指针溢出,但是没明白,求解!
这个是中断位置
这部分的完整代码:
void CLoginDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString c_user, c_password;
//m_user.GetWindowText(c_user);
//m_pwd.GetWindowText(c_password);
GetDlgItemText(IDC_EDIT1,c_user);
GetDlgItemText(IDC_EDIT2, c_password);
if (c_user.IsEmpty() || c_password.IsEmpty())
{
MessageBox(L"用户名称或密码不能为空",L"用户登录信息");
return;
}
CString sql;
sql = L"select * from tb_userinfo where username = '%s' and \
password = '%s'", c_user, c_password;
m_pRs->Open((_variant_t)sql, m_pCon.GetInterfacePtr(), adOpenKeyset,
adLockOptimistic, adCmdText);
if (m_pRs->RecordCount>0)
{
Flag = true;
user = m_pRs->GetCollect("username").bstrVal;
password = m_pRs->GetCollect("password").bstrVal;
EndDialog(0);
}
else
{
user = "";
password = "";
MessageBox(L"用户名或密码不正确.", L"提示", 64);
return;
}
}
sql = L"select * from tb_userinfo where username = '%s' and \
password = '%s'", c_user, c_password;
->
sql = sql.Format("select * from tb_userinfo where username = '%s' and \
password = '%s'", c_user, c_password);
这个错误应该是访问了非法内存导致的。你能先自己打断点,单步找到是哪里(哪一行)报的该错误吗。
因要在这里找的话
m_pRs->Open((_variant_t)sql, m_pCon.GetInterfacePtr(), adOpenKeyset,
adLockOptimistic, adCmdText);
这行着重关注下。
m_pRs注意看一下
你为什么要两个CString 绑定一个ID?