C# C准备的SQL语句不替换@Value

C# C准备的SQL语句不替换@Value,c#,database,sqlite,prepared-statement,C#,Database,Sqlite,Prepared Statement,我得到了这个密码: command = new SQLiteCommand(dbConnection); sql = "SELECT IFNULL(MAX(RowId), 1) AS Id FROM @name"; SQLiteParameter nameParam = new SQLiteParameter("@name", System.Data.DbType.String, 100); command.CommandText = sql; command.Parameters.Add(na

我得到了这个密码:

command = new SQLiteCommand(dbConnection);
sql = "SELECT IFNULL(MAX(RowId), 1) AS Id FROM @name";
SQLiteParameter nameParam = new SQLiteParameter("@name", System.Data.DbType.String, 100);
command.CommandText = sql;
command.Parameters.Add(nameParam);
command.Prepare();

foreach (String name in liste)
{
    command.Parameters[0].Value = name;
    int number = Convert.ToInt32(command.ExecuteScalar());
    ret = ret + number;
}

dbConnection.Close();
return ret;
我做错了什么?执行此语句时,我总是会遇到以下异常:

@name附近:语法错误


这意味着SQLstatement不会被prepared语句参数更新,这是为什么?

不能将表名作为参数传递

您可以在生成SQL语句时将其添加到字符串中,但这样会有SQL注入的风险,所以不要这样做


您可以做的另一件事是让用户从下拉列表中选择表并创建SQL,因为您已经知道所有可能的表。

您不能将表名作为参数传递

您可以在生成SQL语句时将其添加到字符串中,但这样会有SQL注入的风险,所以不要这样做


您可以做的另一件事是让用户从下拉列表中选择表并创建SQL,因为您已经知道所有可能的表。

不能将表名作为参数传递。不能将表名作为参数传递。