【问题标题】:In C#, How can i see if my dataset is empty?在 C# 中,如何查看我的数据集是否为空?
【发布时间】:2022-12-17 13:00:41
【问题描述】:

我最近使用 row.count 来尝试帮助我查看数据集是否为空,是否有其他方法可以判断数据集是否为空? (2022 年更新)

我尝试了 Row.count 并在谷歌上进行了进一步的搜索,但希望人们能直接回答

【问题讨论】:

  • 有时,数据集本身为 null 与没有行之间可能存在差异。
  • 尝试 if (ds.HasChanges() & ds.Tables[0].Rows.Count > 0){ return true;}else{return false;}
  • DataSets 没有行,它们有 Tables(即 DataTables)。一个DataTableRows

标签: c# .net


【解决方案1】:

以下是测试其中的数据集和表的几种方法:

Dataset ds;

if (ds != null) {}  //Check if Dataset is null.

if (ds.Tables.Count > 0) {}  //Check if Dataset has any tables.

if (ds.Tables.Contains("tableName")) {}  //Check if Dataset has a specific table name.

Datatable dt = ds.Tables["tableName"];  //Get the specific table.
if (dt.Rows.Count > 0) {}  //Check if specific table has rows.

if (dt.Columns.Contains("columnName")) {}  //Check if specific table has a specific column name.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 2012-02-28
    • 2016-06-15
    • 2012-11-28
    • 2010-09-22
    • 2010-10-30
    • 2023-03-27
    相关资源
    最近更新 更多