void CDlgLogin::OnOK()
{
CString c_user,c_password;
m_UserName.GetWindowText(c_user);
m_PassWord.GetWindowText(c_password);
if (c_user.IsEmpty() || c_password.IsEmpty())
{
MessageBox("用户名称或密码不能为空", "用户登录信息");
return;
}
CString sql;
try
{
sql.Format("select * from tb_operator where name = '%s' and password = '%s'",c_user,c_password);
m_pRs->raw_Close();
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
catch (_com_error e)
{
// e.Description();
// e.ErrorInfo();
//e.ErrorMessage();
CString str;
str.Format("数据库信息错误%s",e.ErrorMessage());
MessageBox(str,"提示信息",NULL);
}
if (m_pRs->RecordCount>0)
{
Flag = true;
user = m_pRs->GetCollect("name").bstrVal;
password = m_pRs->GetCollect("password").bstrVal;
EndDialog(0);
}
else
{
user = "";
password = "";
MessageBox("用户名或密码不正确.","提示",64);
return;
}
}
调式时 出现 “IDispatch error 3127”错误 MSVCRTD! _CxxThrowException@8 + 57 bytes
_com_raise_error(long -2146824584, IErrorInfo * 0x01f19018) + 35 bytes
_com_issue_errorex(long -2146824584, IUnknown * 0x01f19360, const _GUID & {IID_Recordset15}) + 93 bytes
ADOBS::Recordset15::GetRecordCount() line 680
CDlgLogin::OnOK() line 99 + 24 bytes
哪位高手帮我看看 找了两天还是找不到哪错了
{
CString c_user,c_password;
m_UserName.GetWindowText(c_user);
m_PassWord.GetWindowText(c_password);
if (c_user.IsEmpty() || c_password.IsEmpty())
{
MessageBox("用户名称或密码不能为空", "用户登录信息");
return;
}
CString sql;
try
{
sql.Format("select * from tb_operator where name = '%s' and password = '%s'",c_user,c_password);
m_pRs->raw_Close();
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
catch (_com_error e)
{
// e.Description();
// e.ErrorInfo();
//e.ErrorMessage();
CString str;
str.Format("数据库信息错误%s",e.ErrorMessage());
MessageBox(str,"提示信息",NULL);
}
if (m_pRs->RecordCount>0)
{
Flag = true;
user = m_pRs->GetCollect("name").bstrVal;
password = m_pRs->GetCollect("password").bstrVal;
EndDialog(0);
}
else
{
user = "";
password = "";
MessageBox("用户名或密码不正确.","提示",64);
return;
}
}
调式时 出现 “IDispatch error 3127”错误 MSVCRTD! _CxxThrowException@8 + 57 bytes
_com_raise_error(long -2146824584, IErrorInfo * 0x01f19018) + 35 bytes
_com_issue_errorex(long -2146824584, IUnknown * 0x01f19360, const _GUID & {IID_Recordset15}) + 93 bytes
ADOBS::Recordset15::GetRecordCount() line 680
CDlgLogin::OnOK() line 99 + 24 bytes
哪位高手帮我看看 找了两天还是找不到哪错了
m_pRs->raw_Close();//如果能肯定在这之前没打开过,就把这句去掉
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
另外,你先得看数据库是否打开,就是数据库是否连接,如果数据库没打开,那表肯定打不开.
sql的连接字符串用的是's',这没错,我还没发现有的语法用的是"s".
字符串里的表名和实际的表名否则一致.
单步调试:先看数据库是否连接成功.再看sql的字符串是否正确.
另外,OFFICE2010的连接语句和以前的版本不一样,你的OFFICE是哪个版本的.不过数据库连上就说明连接字符串没问题
hr = m_pConnection->Open( "Provider=Microsoft.Ace.Oledb.12.0;Data Source=D:\\bagayalu.accdb;Jet OLEDB:Database Password=BayAlu良心大大的坏了的111001","", "", adModeUnknown);//这是OFFICE2010版本的
如果是低版本就改成:
hr = m_pConnection->Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\NW.mdb","", "", adModeUnknown);
http://blog.csdn.net/xianglitian/article/details/5617173
还有提示:cannot find PDB file,请教下......