错误的语法附近'='错误
问题描述:
我只是想从我的数据库中检索图像路径,我在运行时提供表名称,但id和太多问题继承人出现的是,它给我错误的语法错误'='错误的语法附近'='错误
这里是我的查询
string query = "select strImage from " + tableName + "where intID ="+Id;
答
您需要的WHERE
子句前添加额外的空间,
string query = "SELECT strImage FROM " + tableName + " WHERE intID ="+Id;
--^HERE
假设变量的值是Hello
,当它被连接在一起,查询将看起来像这样,
SELECT strImage FROM HelloWHERE intID =0
--^lacking space here
答
我希望你的查询是正确的。有一点语法时才problem.Try这
string query = "select strImage from " + tableName + " where intID ="+Id;
答
string query = String.Format("SELECT strImage FROM {0} WHERE intID = {2}", tableName, Id);
字符串结果的串联创建多个对象
这是好的,如果OP使用'.net' –