我正在使用DataReader从我的sqlcommand中读取行。DataReader返回DBNULL
我的问题是,我想返回我的数据库中的所有列 ,错误是他在一列中找到了DBNull。
我该如何解决这个问题?
注意:返回Null的列是字符串类型。
while(sqlDataReader.Read())
{
if (sqlDataReader.HasRows)
{
mylist.Add(new User()
{
Id = (int)sqlDataReader["Id"],
Name = (string)sqlDataReader["Name"],
File= (string)sqlDataReader["File"] <-- This is the one which contains some columns Null
});
}
}
这解决了我的问题..非常感谢你 – user2232273