简单问题:请问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;