【发布时间】:2016-08-17 19:58:06
【问题描述】:
我正在尝试为每一行创建相同的 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 帮助,
等
【问题讨论】:
-
(1) 不能参数化表名。 (2) 如果“UserName”是表的名称,则似乎有问题。
-
(3) OLE DB 在查询文本中需要
?参数标记而不是参数名称。值按序号传递。
标签: sql asp.net sql-server ms-access