我得到一个运行时错误说"Must declare the table variable "@parmTableName"
。这意味着不允许在 sql 语句中将表名作为 sql 参数。
有没有比允许 sql 注入攻击更好的选择或建议?我不想为 sql 语句做这个 C# 脚本" DELETE FROM " + tableName + " "
;
using(var dbCommand = dbConnection.CreateCommand())
{
sqlAsk = "";
sqlAsk += " DELETE FROM @parmTableName ";
sqlAsk += " WHERE ImportedFlag = 'F' ";
dbCommand.Parameters.Clear();
dbCommand.Parameters.AddWithValue("@parmTableName", tableName);
dbConnection.Open();
rowAffected = dbCommand.ExecuteNonQuery();
}