我用 _Recordsetptr 查询数据,是登陆查询,我需要查询帐号和密码是不是错的,用了如下代码
我的帐号是 1111 在m_name 文本框里输入 1111 那么结果就没问题,但是如果输入错误的话那么数据库里肯定就没这记录了
问题是我做了判断,提示帐号错误,但是一到了这行 _variant_t vcount = m_Precordset->GetCollect(Index);
他直接抛出异常,所以下面的代码根本不执行,提示的是异常,而不是帐号错误这提示框,我在网上查了很多种方法,结果一样,只要是输入正确,那么就OK,一旦输入记录里没有的帐号,就抛出异常了
try
{
UpdateData(true);
m_Precordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("select * from Landing where ID ='%s",m_name+"'");
m_Precordset->Open(_bstr_t(strSQL),m_Pconnction.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t Index = (long)0;
_variant_t vcount = m_Precordset->GetCollect(Index);
int count = vcount.lVal;
if ( count == 0 )
{
AfxMessageBox("帐号错误!");
}
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("警告:打开数据库发生异常。\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
我的帐号是 1111 在m_name 文本框里输入 1111 那么结果就没问题,但是如果输入错误的话那么数据库里肯定就没这记录了
问题是我做了判断,提示帐号错误,但是一到了这行 _variant_t vcount = m_Precordset->GetCollect(Index);
他直接抛出异常,所以下面的代码根本不执行,提示的是异常,而不是帐号错误这提示框,我在网上查了很多种方法,结果一样,只要是输入正确,那么就OK,一旦输入记录里没有的帐号,就抛出异常了
try
{
UpdateData(true);
m_Precordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("select * from Landing where ID ='%s",m_name+"'");
m_Precordset->Open(_bstr_t(strSQL),m_Pconnction.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
_variant_t Index = (long)0;
_variant_t vcount = m_Precordset->GetCollect(Index);
int count = vcount.lVal;
if ( count == 0 )
{
AfxMessageBox("帐号错误!");
}
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("警告:打开数据库发生异常。\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
解决方案 »
- 怎么判断输入的是汉字
- 100分求教(急!在线等待!):怎么关闭父窗口的所有子窗口,举个例子父窗口是view 视图,视图中我创建了多个非模式对话框,在视图的析够函数中我想关闭所有的对话框,怎么做?
- 怎样往CTabCtrl中CPropertyPage为基类对话框
- 奇怪了,LoadString()居然会失败!!
- 求助:如何在MFC操作WORD,去掉WORD文档中 某些 文字上已有的超连接?
- 如何在调试过程中使当指定变量变为特定范围是程序中断为当前执行行?
- 同一台机器的进程通信问题?怎样合法关掉子进程?!
- 关于半透明显示的问题?
- 传输丢数据怎么办啊? 高分求急救
- 如何得到kernel,user等windows系统核心模块的句柄?
- 关于atl连接点接口参数问题
- 2k下为什么不能注册activex,XP以上系统就能注册?
{
UpdateData(true);
m_Precordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
strSQL.Format("select * from Landing where ID ='%s",m_name+"'");
m_Precordset->Open(_bstr_t(strSQL),m_Pconnction.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if ( (m_Precordset->BOF)&&(m_Precordset->adoEOF) )
{
AfxMessageBox("帐号错误!");
}
else
{
_variant_t vcount = m_Precordset->GetCollect("字段名");
}
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("警告:打开数据库发生异常。\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
catch(...)
{
}