Can I cast from DBNull to a Nullable Bool in one line?

后端 未结 5 786
南笙
南笙 2021-02-19 04:37

I have a database query which will either return NULL or a boolean (bit) value.

I wish to store this value in a variable of type Nullable<

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-19 05:05

     while (reader.Read()) {
        bool? IsRestricted = (reader.IsDBNull(reader.GetOrdinal("IsRestricted"))) ? (null) : ((bool)reader.GetOrdinal("IsRestricted")));
     }
    

提交回复
热议问题