关键词搜索

源码搜索 ×
×

C# 判断DATASET是否为空

发布2014-01-08浏览13602次

详情内容

  1. if (ds == null)
  2. MessageBox.Show("内存中的数据集为空,说明DATASET为空,行和列都不存在!!");
  3. if (ds.Tables.Count == 0)
  4. MessageBox.Show("内存中存在一个DATASET,但是,数据集中不存在表!!");
  5. if (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0)
  6. MessageBox.Show("存在表table,但是,表内没有数据!");

实用:

  1. /// <summary>
  2. /// 判断DS是否为空
  3. /// </summary>
  4. /// <param name="ds">需要判断的ds</param>
  5. /// <returns>如果ds为空,返回true</returns>
  6. private bool JudgeDs(DataSet ds)
  7. {
  8. bool Flag=false;
  9. if ((ds == null) || (ds.Tables.Count == 0) || (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
  10. {
  11. Flag = true;
  12. }
  13. return Flag;
  14. }
升级版:

  1. /// <summary>
  2. /// 检查一个DataSet 里面是否含有数据
  3. /// </summary>
  4. /// <param name="ds">要检测的DataSet</param>
  5. /// <param name="tableIndex">DataSet里Table的索引</param>
  6. /// <returns>True: 里面有数据。 False:里面没有数据</returns>
  7. public static bool IfExitData(DataSet ds,int tableIndex)
  8. {
  9. if(ds!=null&&ds.Tables[tableIndex].Rows.Count>0)
  10. {
  11. return true;
  12. }
  13. else
  14. {
  15. return false;
  16. }
  17. }



相关技术文章

最新源码

下载排行榜

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载