'='错误附近的语法不正确

时间:2013-01-16 09:42:26

标签: sql select

我只是想从我的数据库中检索图像路径,其中我在运行时提供了表名,但是id也出现问题,因为它在'='

附近给出了错误的语法错误

这是我的查询

string query = "select strImage from " + tableName + "where intID ="+Id;

3 个答案:

答案 0 :(得分:3)

您需要在WHERE子句

之前添加额外空格
string query = "SELECT strImage FROM " + tableName + " WHERE intID ="+Id;
                                                   -- ^ HERE

假设变量tableName的值为Hello,当它连接起来时,查询将如下所示,

SELECT strImage FROM HelloWHERE intID =0
                      --  ^ lacking space here

答案 1 :(得分:1)

我希望您的查询是正确的。有一点语法问题。试试这个

string query = "select strImage from " + tableName + " where intID ="+Id;

答案 2 :(得分:1)

string query = String.Format("SELECT strImage FROM {0} WHERE intID = {2}", tableName, Id);

字符串的连接导致创建多个对象

相关问题