标准表达式中数据类型不匹配

houjie2008 2015-07-31 12:51:56
我用VS2013 FMC做登陆界面 在与数据库进行验证的时候
语句str.Format("select * from login where studentN= '%s' and password = '%d'", m_studentN, m_password);报错
提示标准表达式中数据类型不匹配,求改 求解决 在线等
...全文
300 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
我爱大家369 2015-08-21
  • 打赏
  • 举报
回复
CString 对象的 AllocSysString 方法将 CString 转化成 BSTR: CString s; s = ... ; // whatever BSTR bstr = s.AllocSysString(); ... 使用完成以后: SysFreeString(bstr);// 用完释放
houjie2008 2015-07-31
  • 打赏
  • 举报
回复
引用 1 楼 houjie2008 的回复:
try { CString str; str.Format("select * from login where studentN= '%s' and password = '%d'", m_studentN, m_password); BSTR bstrSQL = str.AllocSysString(); this->m_pRecordset->Open(bstrSQL, (IDispatch*)this->m_pConnection, adOpenDynamic, adLockOptimistic, adCmdText); } catch (_com_error e) { // 显示错误信息 AfxMessageBox(e.Description()); }
这个是这一段代码 求大神指教
houjie2008 2015-07-31
  • 打赏
  • 举报
回复
try { CString str; str.Format("select * from login where studentN= '%s' and password = '%d'", m_studentN, m_password); BSTR bstrSQL = str.AllocSysString(); this->m_pRecordset->Open(bstrSQL, (IDispatch*)this->m_pConnection, adOpenDynamic, adLockOptimistic, adCmdText); } catch (_com_error e) { // 显示错误信息 AfxMessageBox(e.Description()); }
boylafong 2015-07-31
  • 打赏
  • 举报
回复
CString str; str.Format("select * from login where studentN= '%s' and password = '%d'", m_studentN, m_password); BSTR bstrSQL = str.AllocSysString(); this->m_pRecordset->Open(bstrSQL, (IDispatch*)this->m_pConnection, adOpenDynamic, adLockOptimistic, adCmdText); 这句话没什么问题啊? 用的什么字符集?
二班的码农 2015-07-31
  • 打赏
  • 举报
回复
估计是字符集的问题,用_T(),支持Unicode编码 将代码改成 str.Format(_T("select * from login where studentN= '%s' and password = '%d'"), m_studentN, m_password); 试试
houjie2008 2015-07-31
  • 打赏
  • 举报
回复
引用 3 楼 boylafong 的回复:
写的很明白啊,类型不符啊 CString是动态的TCHAR数组。它是一个完全独立的类,封装了+等操作符和字符串操作方法。 而BSTR是专有格式的字符串,定义为:typedef OLECHAR FAR* BSTR 上面两位告诉了你怎么转换
。。。上面那两个代码就是我的。。。
boylafong 2015-07-31
  • 打赏
  • 举报
回复
写的很明白啊,类型不符啊 CString是动态的TCHAR数组。它是一个完全独立的类,封装了+等操作符和字符串操作方法。 而BSTR是专有格式的字符串,定义为:typedef OLECHAR FAR* BSTR 上面两位告诉了你怎么转换

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧