我只想从我的数据库中检索图像路径,我在运行时提供表名,但是 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);
字符串的连接导致创建多个对象