Skip to content

Parametize ALTER TABLE ??? Help!

zsing

Asked May 19, 2009, 1:39 AM EDT2 answers
Share
LinkedInX
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 :(

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Instead of using Query try using a stored procedure.
    0
  • 0
    Stored procedure? Is it possible to parametize a stored procedure? I need a table to store some vectors. I must calculate the dimension of the vector space, and then to build the table, with this parameters.
    Ex: V(0.2 4.5 2.1 0.0 5.1 1.0........). This is a document vector, and its dimension would be, the no. of distinct words in a document collection.
    0