无法将数据表列值转换为可为空的int32

时间:2016-12-15 11:28:37

标签: c# linq datatable ado.net

下面是我的类定义,用于从mssql和mysql获取列详细信息:

public class Columns
    {
        public string Name { get; set; }
        public string Datatype { get; set; }
        public string IsNullable { get; set; }
        public Int32? character_maximum_length { get; set; }
        public byte? NumericPrecision { get; set; }
        public Int32? NumericScale { get; set; }
    }

基于documentation我选择 Int32 ?,字节?和int32表示character_maximum_length,数字位置和数字刻度属性

现在,当我填写列详细信息时,这适用于mssql:

 cols = con.GetSchema("Columns", columnRestrictions).AsEnumerable()
       .Select
       (
              col => new Columns
              {
                Name = col[3].ToString(),//name of column
                Datatype = col.Field<string>("DATA_TYPE"),
                IsNullable = col.Field<string>("is_nullable"),
                character_maximum_length = col.Field<Int32?>("character_maximum_length"),
                NumericPrecision = col.Field<byte?>("NUMERIC_PRECISION"),
                NumericScale = col.Field<Int32?>("NUMERIC_SCALE")
               }).ToList();

我在mysql的情况下使用相同的类填充列详细信息但在下面的行中出现错误:指定的强制转换无效

  character_maximum_length = (Int32?) col[8] // in case of mysql

没有文档说明在mysql的情况下character_maximum_length,数字位置和数字刻度的数据类型是什么。

我检查了character_maximum_length的数据类型,如下所示:

enter image description here

但我想保持我的列类对于mysql和mssql 都相同。

那么我该如何解决这个问题?

0 个答案:

没有答案
相关问题