How to change the column property of a column of a database table using SMO.
I use SMO to manage the SQL Server 2005.
I want to change a existing column of a database table to be the same with the other column.
I used the following code but it has an error while calling Column.Alter() function.
public void RepairColumns(object dcolumn)
{
try
{
Column d_Column = (Column)dcolumn;
Column l_Column = mServer.Databases[mSMOInfo.DBName].Tables[mSMOInfo.TableIndex].Columns[mSMOInfo.ColumnIndex];
l_Column.Collation = d_Column.Collation;
l_Column.Computed = d_Column.Computed;
l_Column.ComputedText = d_Column.ComputedText;
l_Column.DataType = d_Column.DataType;
l_Column.Default = d_Column.Default;
l_Column.Identity = d_Column.Identity;
l_Column.IdentityIncrement = d_Column.IdentityIncrement;
l_Column.IdentitySeed = d_Column.IdentitySeed;
l_Column.NotForReplication = d_Column.NotForReplication;
l_Column.Nullable = d_Column.Nullable;
l_Column.RowGuidCol = d_Column.RowGuidCol;
l_Column.Rule = d_Column.Rule;
l_Column.RuleSchema = d_Column.RuleSchema;
l_Column.IsPersisted = d_Column.IsPersisted;
l_Column.DefaultSchema = d_Column.DefaultSchema;
l_Column.Alter();
}
catch (SmoException ex)
{
throw ex;
}
}
If u know my wrong coding, pls point me.
Thanks ^.^