首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

简单有关问题:请教vc下sql2000为什么不能用变量

2012-04-08 
简单问题:请问vc下sql2000为什么不能用变量?代码简写如下:CStringsSQL;CStringtemptemp 3 _Connectio

简单问题:请问vc下sql2000为什么不能用变量?
代码简写如下:
CString   sSQL;
CString   temp;
temp= "3 ";
_ConnectionPtr   pConn(__uuidof(Connection));

sSQL= "select   *   from   rt000666   Where   Pressure0   > =temp ";
pConn-> Execute((_bstr_t)sSQL,NULL,adCmdText);

问题:如果在sSQL中把temp换成 '3 ',程序结果正常。
如果用变量temp,则执行到pConn-> Execute((_bstr_t)sSQL,NULL,adCmdText);时就会出错,这是为什么?为什么字符串可以而字符串变量就会出错?


[解决办法]
temp在里面只是一个 "temp ",不要以为是变量temp,不会替代的
sSQL= "select * from rt000666 Where Pressure0 > = ";
sSQL+=temp;
[解决办法]
把sSQL= "select * from rt000666 Where Pressure0 > =temp ";
改成sSQL = "select * from rt000666 Where Pressure0 > = " + temp;

热点排行