关于sql字符串的问题

bnm77 2012-12-24 11:21:29
m_pRecordset->Open("SELECT * FROM datadb where No>'12345'",
m_pConnection.GetInterfacePtr(),
adOpenStatic,
adLockOptimistic,
adCmdText);

如何用一个字符串变量代替"SELECT * FROM datadb where No>'12345'"。

譬如:
Cstring Str="SELECT * FROM datadb where No>'12345'";
m_pRecordset->Open(Str,
m_pConnection.GetInterfacePtr(),
adOpenStatic,
adLockOptimistic,
adCmdText);
...全文
96 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
傻X 2012-12-24
  • 打赏
  • 举报
回复
楼主,你这是啥意思啊? Cstring Str="SELECT * FROM datadb where No>'12345'";不就可以了嘛? 注意转义符就好
快乐鹦鹉 2012-12-24
  • 打赏
  • 举报
回复
你不都写完了么?
bnm77 2012-12-24
  • 打赏
  • 举报
回复
引用 6 楼 toucheme 的回复:
m_pRecordset->Open(_variant_t(Str), m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText);
正确
bnm77 2012-12-24
  • 打赏
  • 举报
回复
引用 7 楼 qimiao77 的回复:
Cstring Str="SELECT * FROM datadb where No>'12345'"; pRecordset->Open((_bstr_t)Str,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
正确 !
贪玩的老鼠 2012-12-24
  • 打赏
  • 举报
回复
Cstring Str="SELECT * FROM datadb where No>'12345'"; pRecordset->Open((_bstr_t)Str,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
toucheme 2012-12-24
  • 打赏
  • 举报
回复
m_pRecordset->Open(_variant_t(Str), m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText);
bnm77 2012-12-24
  • 打赏
  • 举报
回复
错误提示: error C2664: 'Open' : cannot convert parameter 1 from 'class CString' to 'const class _variant_t &' Reason: cannot convert from 'class CString' to 'const class _variant_t'
toucheme 2012-12-24
  • 打赏
  • 举报
回复

	catch(_com_error &e)
	{
		CString sError = (LPCTSTR)e.Description();
		OutMessage(HTT_ERROR, sError);
		return;
	}
捕获一下,看看错误提示是什么
bnm77 2012-12-24
  • 打赏
  • 举报
回复
Cstring Str="SELECT * FROM datadb where No>'12345'"; m_pRecordset->Open(Str, m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText); 总提示出错...........

4,011

社区成员

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

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