日期:2014-05-18  浏览次数:21161 次

新手提个简单问题
if(ds.Tables [0].Rows .Count >0) 

{
........
}

else
{
messagebox.show("没有记录");
}
-------------------------------------
dataset返回值是null,得到count=1,所以count>0,不能跳到else的提示
想问问怎么判断dataset返回为null,然后到else去。
(if (ds==null)试过了,也不行)
很是郁闷,有高人告诉下

------解决方案--------------------
if(ds!=null && ds.Tables.Count>0 && ds.Tables [0]!=null && ds.Tables [0].Rows .Count >0) 
{ 
........ 
} 

else 
{ 
messagebox.show("没有记录"); 
} 

  
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 

http://feiyun0112.cnblogs.com/
------解决方案--------------------
在SQL中
Select ISNULL(t2,0) AS t2 from table

或者在代码中判断

if(ds!=null && ds.Tables.Count>0 && ds.Tables [0]!=null && ds.Tables [0].Rows .Count >0) 
{ 
if (ds.Tables[0].Rows[0]["t2"] is DBNull)//ds.Tables[0].Rows[0]["t2"] == DBNull.Value
} 

else 
{ 
messagebox.show("没有记录"); 
}