SQL Data Reader - handling Null column values

前端 未结 27 2585
甜味超标
甜味超标 2020-11-22 08:53

I\'m using a SQLdatareader to build POCOs from a database. The code works except when it encounters a null value in the database. For example, if the FirstName column in the

27条回答
  •  梦谈多话
    2020-11-22 09:12

    reader.IsDbNull(ColumnIndex) works as many answers says.

    And I want to mention if you working with column names, just comparing types may be more comfortable.

    if(reader["TeacherImage"].GetType() == typeof(DBNull)) { //logic }
    

提交回复
热议问题