Trying to create SQL tables in ado.net with code. I've been using the parameterized query to create the table which works but im also getting an second table with the name @name which is obvious because im passing it too. Now my question is how do i prevent the table creating of @name ?
Here is my query
public void CreateTable(string name)
{
string connectionString = @"Data Source=tcp:SRV-SKYSPARK,1434;Initial Catalog=Trevi-NV;Integrated Security=True;Pooling=False";
string query =
@"CREATE TABLE [dbo].[@name] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[TimeStamp] DATETIME NOT NULL,
[TagName] NCHAR (64) NOT NULL,
[Value] NCHAR (32) NOT NULL,
[TagType] NCHAR (64) NULL,
[Description] NCHAR (128) NULL
);";
using (SqlConnection cn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(query, cn))
{
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = name;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}