好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何使用c#查找SQL Server中的值是否为NULL

我想知道从SqlHelper类的ExecuteDataTable返回的c#中的数据表中哪些值为null.

string select = "select * from testTable";
string val="";

DataTable  dt=dbcon.ExecuteDataTable(select);
foreach (DataRow dr in dt.Rows)
{
   foreach (DataColumn  dc in dt.Columns )
   {
       if(dr[dc].Equals (null))
       {
          val ="null";
       } 
       else  
       {
          val = dr[dc].ToString();
       }
   }
}

但不幸的是,我没有找到任何办法.如果有办法,请告诉我.先感谢您.

除了David M的方法,您还可以使用 DataRow.IsNull:

if (dr.IsNull(dc))

查看更多关于如何使用c#查找SQL Server中的值是否为NULL的详细内容...

  阅读:38次