c # bool value read from the database

This database bit Boolean field, very practical, but when reading in c #, many people like to make mistakes, leading to operational error.

In practice, correct and effective method of reading only the following two ways:

 

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

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

 

Others are likely to be an error, even if no error, there is no guarantee database settings or operating system, leading to a sudden being given!

As int.Parse (), sometimes it will tell me the error:

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

Guess you like

Origin www.cnblogs.com/snowguest/p/11871065.html