vc连接sql server的一个查询问题 急!!!!!!

yuzhuo0820 2007-07-27 09:33:45
我想做一个类让它灵活的应用到对每张表的查询上,但遇到一问题
getDate(CString table,CString *p)

try
{

CString connect="select * from";
connect+=datebase;
m_pRecordset->Open( connect , // cn.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
为什么这样写为什么老是说类型不匹配呢?
问题出在那里

还有如果我要有条件的查询一张表同样出现这样的问题
try
{

m_pRecordset->Open( "select *from admin
where adminID=m_test" ,
cn.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}

其中m_test是手动通过编辑框输入的 是CString类型
为什么这样写还是有问题
m_pRecordset->Open( "select *from admin
where adminID='m_test'"
把他写成这样还是不对

请高人指点 很急

...全文
285 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuzhuo0820 2007-07-27
  • 打赏
  • 举报
回复
多谢了
问题解决了
网上的高手还是多啊
yuzhuo0820 2007-07-27
  • 打赏
  • 举报
回复
楼上的那种写法编译是没有问题
但是在运行的时候就有问题了
handsomerun 2007-07-27
  • 打赏
  • 举报
回复
CString str;
str.Format("select *from admin where adminID='%s'",datebase);
m_pRecordset->Open(_bstr_t(str),
。。。。。。。。。。。。。。。。。。。。。。。。。

。。。。。。。。。。。。。。。。。
happynxy 2007-07-27
  • 打赏
  • 举报
回复
m_pRecordset->Open( str.AllocSysString ( ) , //这里改一下
cn.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
yuzhuo0820 2007-07-27
  • 打赏
  • 举报
回复
CString str;
str.Format("select *from admin where adminID='%s'",datebase);
m_pRecordset->Open( str ,
cn.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
这样写好象还不对啊
yuzhuo0820 2007-07-27
  • 打赏
  • 举报
回复
多谢了
quiton 2007-07-27
  • 打赏
  • 举报
回复
CString str;
str.Format("select *from admin
where adminID='%s'",m_test);


4,011

社区成员

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

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