日期:2014-05-17  浏览次数:20822 次

我发现了一个奇怪的问题,如何判断DataTable的是否为空?大家来研究一下吧
            DataSet ds = new DataSet();
            DataTable codeTable = ds.Tables[0];
            if (codeTable.Rows.Count != 0)
            {
               //不为空就进来
            }

codeTable != null 和 codeTable.Rows.Count 这两个方法是错误的,大家来研究一下吧

------解决方案--------------------
引用:
            DataSet ds = new DataSet();
            DataTable codeTable = ds.Tables[0];
            if (codeTable.Rows.Count != 0)
            {
               //不为空就进来
            }

codeTable != null 和 codeTable.Rows.Count 这两个方法是错误的,大家来研究一下吧


你发这样的代码上来如何改ds缓存里面压根没有表,第二行代码就错了
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

Quote: 引用:


DataSet ds = new DataSet();
if(ds!=null)
{
   DataTable codeTable = ds.Tables[0];
   if (codeTable.Rows.Count != 0)
   {
      //不为空就进来
   }
}


俺写了个错误的东西出来,楼主请无视,,