用DataReader读取数据怎样判断当前记录的某列是否为空 :
//调用:
if (ReaderExists(dr, "Log_ID"))
model.Log_DoctorID = GetInt(dr["Log_ID"]);
/// <summary>
/// 判断 DataReader 里面是否包含指定的列
/// </summary>
/// <param name="dr"></param>
/// <param name="columnName"></param>
/// <returns></returns>
public static bool ReaderExists(DbDataReader dr, string columnName)
{
int count = dr.FieldCount;
for (int i = 0; i < count; i++)
{
if (dr.GetName(i).Equals(columnName))
{
return true;
}
}
return false;
}
/// <summary>
/// 判断 DataReader 里面是否包含指定的列
/// </summary>
/// <param name="dr"></param>
/// <param name="columnName"></param>
/// <returns></returns>
public static bool ReaderExists2(DbDataReader dr, string columnName)
{
dr.GetSchemaTable().DefaultView.RowFilter = "ColumnName= '" + columnName + "'";
return (dr.GetSchemaTable().DefaultView.Count > 0);
}
推荐使用第一种方式,基本不存在性能损耗