【发布时间】:2013-01-16 09:42:25
【问题描述】:
我只想从我的数据库中检索图像路径,我在运行时提供了表名,但是 id 也出现了问题,它给了我在 '=' 附近语法不正确的错误
这是我的查询
string query = "select strImage from " + tableName + "where intID ="+Id;
【问题讨论】:
我只想从我的数据库中检索图像路径,我在运行时提供了表名,但是 id 也出现了问题,它给了我在 '=' 附近语法不正确的错误
这是我的查询
string query = "select strImage from " + tableName + "where intID ="+Id;
【问题讨论】:
您需要在WHERE 子句之前添加额外的空格,
string query = "SELECT strImage FROM " + tableName + " WHERE intID ="+Id;
-- ^ HERE
假设变量tableName的值为Hello,当它被连接起来时,查询将是这样的,
SELECT strImage FROM HelloWHERE intID =0
-- ^ lacking space here
【讨论】:
我希望您的查询是正确的。语法有点问题。试试这个
string query = "select strImage from " + tableName + " where intID ="+Id;
【讨论】:
string query = String.Format("SELECT strImage FROM {0} WHERE intID = {2}", tableName, Id);
字符串的连接导致创建多个对象
【讨论】:
.net,这很好