SQLDMO.SQLServer2 svr = new SQLDMO.SQLServer2Class();
svr.Connect(ServerName, UserName, Password);
SQLDMO.Database2 myDb = new SQLDMO.Database2Class();
myDb = (SQLDMO.Database2)svr.Databases.Item(DatabaseName, "owner");
SQLDMO.Table2 myTb = new SQLDMO.Table2Class();
foreach (SQLDMO.Table2 tb in myDb.Tables)
{
    if (tb.Name == TableName)
    myTb = tb;
}
SQLDMO.Column2 cm = (SQLDMO.Column2)myTb.Columns.Item(ColumnName);修改成为varchar,nvarchar类型的时候
cm.AlterDataType("Numeric",9,9, 3);     成功修改为int的时候
cm.AlterDataType("int",4,9, 0);   出错到底 AlterDataType方法修改字段为int类型的时候,怎样的参数才可以??

解决方案 »

  1.   

    have a try:cm.AlterDataType("int",4,0, 0);
      

  2.   

    Syntaxobject.AlterDataType( Datatype , [ Length ] , [ Precision ] , [ Scale ] )
    objectExpression that evaluates to an object in the Applies To listDataTypeString that specifies the new data typeLengthOptional long integer that specifies the length of a string data typePrecisionOptional long integer that specifies the precision of a numeric data typeScaleOptional long integer that specifies the scale of a numeric data type.Prototype (C/C++)HRESULT AlterDataType(
    SQLDMO_LPCSTR DataType,
    long Length,
    long Precision,
    long Scale);ResWhen using AlterDataType to convert the data type of an existing column to a new data type, the two data types must be compatible. For example, an int data type can be converted to a decimal data type, and a char data type can be converted to an nvarchar data type. However string data types cannot be converted to numeric data types.
    试试 cm.AlterDataType("int");
      

  3.   

    To Edifier0709(腦袋重構中.....)cm.AlterDataType("int",4,0, 0);  试过,抱错。to oolongTea(乌龙茶)cm.AlterDataType("int");  不可以,因为必须传递4个参数。   在visual basic 里面是可以的
      

  4.   

    string data types cannot be converted to numeric data types
    --
    字符型不能转换数值型报的什么错?
      

  5.   

    连接数据库出错:[Microsoft][ODBC SQL Server Driver][SQL Server]第 0 个列或参数: 不能对数据类型 int 指定列宽度。转成其他类型都没有错,就是int类型头疼。
      

  6.   

    cm.AlterDataType("int",-1, -1, -1);  用-1行不行?
      

  7.   

    zxkid(Born in heaven, die in hell: everybody has sins !) 果然是牛人!用cm.AlterDataType("int",-1, -1, -1);  正确修改字段成为int类型非常感谢! 结贴!