I have some SQL Queries written in my C# code.Table names are passing to the constructor using an enum.Then it assign to a global variable and append to the string,
const string ADD_SQL = "INSERT INTO {0} (ColumnOne) VALUES (@valueOne)";
const string CLEAR_SQL = "DELETE FROM {0}";
var commandText = string.Format(ADD_SQL , _tableName);
But when I am running Veracode tool it shows this query has possibility of SQL Injection when going to execute.
command.ExecuteNonQuery();
Any possible solution to avoid this SQL Injection scenario from the code.Need a recfatoring to the above const.I tried with adding a tag (@tablename) and tried.But it is not succeeded.
const string ADD_SQL = "INSERT INTO @tablename (Data) VALUES (@valueOne)";
var commandText = ADD_MESSAGE_SQL.Replace("@tablename", _tableName);
Any other possible solution to avoid this?