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

后端 未结 5 785
南笙
南笙 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:02

    You can just do the following

    bool? myNullableBoolean = SqlConvert.ToType(reader["myNullableBooleanColumn"]);

提交回复
热议问题