使用reader.GetValue()时,如果数据库中有空值,会返回DBNull.Value。相关代码如下:
// System.Data.SqlClient.SqlDataReader private object GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaData) { if (this._typeSystem <= SqlConnectionString.TypeSystem.SQLServer2005 && metaData.IsNewKatmaiDateTimeType) { if (data.IsNull) { return DBNull.Value; } } ... }
DBNull.Value实现了ToString()操作,会返回空字符串。相关代码如下:
// System.DBNull public override string ToString() { return string.Empty; }
OK ,了解了,多谢