数据库里bit这个布尔类型的字段,非常实用,但是在c#里读取时,许多人喜欢犯一些错误,导致运行报错。

实际中,有效的正确读取方法只有以下两种:

 

int xxx= Convet.ToInt16(reader["xxx"]);//或Convet.ToInt32

bool xxx= bool.Parse(reader["xxx"]);

 

其他的都有可能会报错,即便不报错,也不能保证数据库设置或操作系统的问题,导致突然报错了!

如int.Parse(),有时就会报一下错误:

在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2021-08-03
  • 2021-07-09
  • 2021-08-22
猜你喜欢
  • 2022-02-26
  • 2021-10-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案