用VS 2008 VB检测MySQL字段中的zerofill

时间:2011-07-27 01:40:38

标签: mysql vb.net visual-studio-2008 zerofill

使用.NET连接器:http://dev.mysql.com/doc/refman/5.1/en/connector-net-ref.html

在MySQL中将字段设置为:

decimal(6) zerofill not null

如何在VB中检测到“zerofill”标志?

1 个答案:

答案 0 :(得分:1)

您可以使用SHOW COLUMNS IN tablename获取列信息,此查询将返回以下格式的内容:

field         type                          null   key   default    extra
fieldname     int(10) unsigned zerofill      no            0    

因此,要获取标志zerofill,如果int中返回的字符串包含'zerofill'字符串,则必须查看类型:

这样的事情可以解决问题:

static void Main(string[] args)
{
    dim conn as MySqlConnection
    conn = new MySqlConnection
    conn.ConnectionString = "Server = yourserver; Database = yourdb; Uid = youruser;Pwd = yourpassword;"

    conn.Open

    MySqlCommand cmd = new MySqlCommand
    cmd.Connection = conn
    cmd.CommandText = "SHOW COLUMNS IN yourtable"
    cmd.CommandType = CommandType.Text

    dim reader as MySqlDataReader
    reader = cmd.ExecuteReader

    while reader.Read
        Console.WriteLine("Field:{0}, zerofill:{1}",reader("field"),if(reader("type").ToString().Contains("zerofill"),true,false))
    end while
    conn.Close()
}