2
Answers

Parametize ALTER TABLE ??? Help!

Ask a question
zsing

zsing

15y
2.8k
1
I want to modify a table's structure with a method.
Please help how to write this method!
I've tried:

public void tableExpand(string tableName, string colName)
{
...................

dataCommand.CommandText =
"ALTER TABLE @tableName" +
"ADD @colName real";

SqlParameter tableParam = new SqlParameter();
tableParam .ParameterName = "@tableName";
tableParam .Value = tableName;

SqlParameter colParam = new SqlParameter();
colParam .ParameterName = "@colName";
colParam .Value = colName;

dataCommand.Parameters.Add(tableParam);
dataCommand.Parameters.Add(colParam);

.....................
}

But this isn't the right way :(

Answers (2)