簡體   English   中英

計算數據表中的數據行[]

[英]Count the datarow from datatable[]

我有1個數據集和4個datable。 那么如何計算這些數據表的每一行呢?

DataTable[] ret = 
{
    new DataTable(), 
    new DataTable(), 
    new DataTable(), 
    new DataTable()
};

for (int i = 0; i < 4; i++)
{
    DataTable table = new DataTable();
    table.Columns.Add("Delivery Date", typeof (string));
    table.Columns.Add("Ord.Qty", typeof (string));
    table.Columns.Add("Balance", typeof (string));
    ret[i] = table;
}

此1是計算4個數據表的總行。

int rowCount = ds.Tables[0].Rows.Count;

要將每個表的行數分別放入整數數組,請使用-

 var count = ret.Select(table => table.Rows.Count);

要獲取所有表中的總行數,請使用-

 var sumOfRowCount = ret.Select(table => table.Rows.Count).Sum();

這里只是黑暗中的一槍...

var count = 0;

foreach (var t in ds.Tables)
{
    count += t.Rows.Count;
}

可能對您有用-

    DataSet ds = new DataSet();
    // just add your tables in this **ds**.

    int totalRows = 0;

    foreach (DataTable dt in ds.Tables)
    {
        foreach (DataRow dr in dt.Rows)
            totalRows++;
    }

    Response.Write(totalRows.ToString());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM