DataTable table = .... if (table != null && table.Rows.Count > 0) { if (table.Rows[0]["columnname"] is DBNULL) { //这个字段为NULL } }
都是好办法,也可以数据库里面做啊, name=case when name is null then "null",然后在c#里面见到null的名字就特殊处理一下,DBNull.ValueDataTable table = .... if (table != null && table.Rows.Count > 0) { if (table.Rows[0]["columnname"] is DBNULL) { //这个字段为NULL } }
2,在程序里判断是否为DBNull.Value
{
//
}
if (table != null && table.Rows.Count > 0)
{
if (table.Rows[0]["columnname"] is DBNULL)
{
//这个字段为NULL
}
}
if (table != null && table.Rows.Count > 0)
{
if (table.Rows[0]["columnname"] is DBNULL)
{
//这个字段为NULL
}
}