查询中的SELECT语法错误。不完整的查询条款

时间:2016-04-24 13:00:27

标签: sql asp.net sql-server ms-access

我正在尝试为每一行创建相同的SQL SELECT。

但是,我在'showReader = sqlShowSol.ExecuteReader();'

中遇到了问题

它说 - “查询中的语法错误。不完整的查询条款。”

为什么?

-- connection was established before. --

        System.Data.OleDb.OleDbCommand sqlShowSol = new System.Data.OleDb.OleDbCommand();
        sqlShowSol.Connection = connection;

        System.Data.OleDb.OleDbDataReader showReader;

        int row = 1;

        while (true)
        {

            sqlShowSol.CommandText = "SELECT Q_A,Content FROM @userName WHERE id = @id;";
            sqlShowSol.Parameters.AddWithValue("@userName", userName);
            sqlShowSol.Parameters.AddWithValue("@id", row);
            showReader = sqlShowSol.ExecuteReader();

|-----------------------------------------------------------------------------------------|

There is more code afterwords...
But I get the problem in the last line I typed here.

Tnx 4帮助,

Etay

1 个答案:

答案 0 :(得分:0)

当你这样写:

"SELECT Q_A,Content FROM @userName WHERE id = @id;";

您使用的参数不正确。您不能使用参数作为表名。数据库引擎无法解释@userName引用。