I used the following code as an attempt to parametermize a table name of a SQL Server 2005 database.
However, I got the error message in attached picture. I was asked for a "table variable", but I don't know how to declare it. Can you help me to make the code work without using Ac-Hoc method such as string concatenation and hard-coding?
Thank you very much!
System.Data.SqlClient.SqlConnection Connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
System.Data.SqlClient.SqlCommand Command = Connection.CreateCommand();
Command.CommandType = CommandType.Text;
Command.CommandText = "UPDATE @TableName SET Name = @Name, WHERE Id = @Id";
Command.Parameters["TableName"].Value = "Building";
Command.Parameters["Id"].Value = 1;
Command.Parameters["Name"].Value = "Inventory1";