一条SQl语句的问题
strSQL= "select * from user where "+searchtype+ "like '% "+searchkey+ "% ' ";
请问这句有错误吗?谢谢!
------解决方案--------------------strSQL= "select * from user where "+searchtype+ "like '% "+searchkey+ "% ' ";
改成下面的,加空格
strSQL= "select * from user where "+searchtype+ " like '% "+searchkey+ "% ' ";
------解决方案--------------------strSQL= "select * from user where ' "+searchtype+ " 'like '% "+searchkey+ "% ' ";
------解决方案--------------------同意huang2007xiang() 的改法,但是要注意一下在有的数据库中user表是系统表(比如sqlserver),可以改为
strSQL= "select * from [user] where "+searchtype+ " like '% "+searchkey+ "% ' ";
------解决方案--------------------strSQL= "select * from [user] where "+searchtype+ " like '% "+searchkey+ "% ' ";
------解决方案--------------------同意楼上的
------解决方案--------------------javaboy2006 正解
------解决方案--------------------最好是:
strSQL= "select * from [user] where "+searchtype+ " like '% "+searchkey+ "% ' ";
------解决方案--------------------测试SQL文 就先在控制台打印出来 然后到数据库里试
------解决方案--------------------一看就没空格啊,肯定会有问题了
------解决方案--------------------你的like左右两边都是变量,没有数据库字段,你改一个字段试一下