【问题标题】:MySqlDbType tiny(4) doesn't existMySqlDbType tiny(4) 不存在
【发布时间】:2018-07-03 18:59:34
【问题描述】:

我正在向 MySqlCommand 添加参数,并且我有一个声明为 Tiny(4) 的列,但 MySqlDbType 中不存在该类型。 我的代码中的数据也是字符串“0”或“1”。

 If ActiveModifChk.Checked Then
        ActiveStr = "1"
 Else
        ActiveStr = "0"
 End If

 cmd.Parameters.Add("@isActive", MySqlDbType.Int16).Value = ActiveStr

我应该使用什么 MySqlDbType?

【问题讨论】:

  • TinyInt 相当于 .net 中的 Byte 或 SByte

标签: mysql vb.net winforms


【解决方案1】:

根据MySqlDbType enumeration reference,根据有符号或无符号定义使用MySqlDbType.ByteMySqlDbType.UByte 来处理tinyint 数据类型:

// signed 8-bit
cmd.Parameters.Add("@isActive", MySqlDbType.Byte).Value = sbyte.Parse(ActiveStr);

// unsigned 8-bit
cmd.Parameters.Add("@isActive", MySqlDbType.UByte).Value = byte.Parse(ActiveStr);

如果您只是传递“零”或“一”(类似于truefalse 条件),请使用MySqlDbType.Bit 并将bit 数据类型定义到相应的参数/列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2011-10-03
    • 1970-01-01
    • 2021-04-15
    • 2019-03-30
    • 2011-12-22
    • 2012-06-12
    相关资源
    最近更新 更多