I have the following SQL query which takes the header from a file and creates a column with the same name as the header:
SqlCommand createtable = new SqlCommand("CREATE TABLE " + tbXLSTableName.Text + " (" + dc.ColumnName + " varchar(MAX))", myConnection);
It is open for an SQL injection attack so I decided to use parameters like this:
string strCreateTable = "CREATE TABLE @TableNameCreateXLS (" + dc.ColumnName + " varchar(MAX))";
SqlCommand createtable = new SqlCommand(strCreateTable, myConnection);
createtable.Parameters.AddWithValue("TableNameCreateXLS", tbXLSTableName.Text);
dc is a DataColumn object.
I am getting the following error:
Incorrect syntax near @TableNameCreateXLS
How can I resolve the error?