为tinyint和bigint数据类型

时间:2017-01-05 08:38:16

标签: c# mysql .net ado.net

下面是我的mysql表:

enter image description here

我正在尝试从这些表中获取以下信息:

Column Name
Datatype
Size
Numeric Precision
Numeric Scale

以下是我想要获得最终输出的课程:

public class MySqlColumns
    {
        public string Name { get; set; }
        public string Datatype { get; set; }
        public string IsNullable { get; set; }
        public UInt64? Size { get; set; }
        public UInt64? NumericPrecision { get; set; }
        public UInt64? NumericScale { get; set; }
    }



using (MySqlConnection con = new MySqlConnection(connectionString))
            {
                con.Open();
                String[] columnRestrictions = new String[4];
                columnRestrictions[1] = "student";
                columnRestrictions[2] = "test";
                list = con.GetSchema("Columns", columnRestrictions).AsEnumerable()
                              .Select
                              (
                                   col => new MySqlColumns
                                   {
                                       Name = col[3].ToString(),//name of column
                                       Datatype = col.Field<string>("DATA_TYPE"),
                                       IsNullable = col.Field<string>("is_nullable"),
                                       Size = col.Field<UInt64?>("character_maximum_length"),
                                       NumericPrecision = col.Field<UInt64?>("NUMERIC_PRECISION"),
                                       NumericScale = col.Field<UInt64?>("NUMERIC_SCALE")
                                   }
                              ).ToList();
                con.Close();
            }

现在对于bigint,我得到精度为19,因为它是20,而对于tinyint,当精度为7时,我总是得到精度为3。

来源https://msdn.microsoft.com/en-us/library/cc716722(v=vs.110).aspx

所以有人可以帮我解决这个问题吗?

0 个答案:

没有答案