简体   繁体   English

迭代DataSet

[英]Iterate through DataSet

I have a DataSet named DataSet1 . 我有一个名为DataSet1DataSet It contains an unknown number of tables and an unknown number of columns and rows in those tables. 它包含未知数量的表以及这些表中未知数量的列和行。 I would like to loop through each table and look at all of the data in each row for each column. 我想遍历每个表并查看每列的每行中的所有数据。 I'm not sure how to code this. 我不知道如何编码。 Any help would be appreciated! 任何帮助,将不胜感激!

foreach (DataTable table in dataSet.Tables)
{
    foreach (DataRow row in table.Rows)
    {
        foreach (object item in row.ItemArray)
        {
            // read item
        }
    }
}

Or, if you need the column info: 或者,如果您需要列信息:

foreach (DataTable table in dataSet.Tables)
{
    foreach (DataRow row in table.Rows)
    {
        foreach (DataColumn column in table.Columns)
        {
            object item = row[column];
            // read column and item
        }
    }
}

Just loop... 只是循环......

foreach(var table in DataSet1.Tables) {
    foreach(var col in table.Columns) {
       ...
    }
    foreach(var row in table.Rows) {
        object[] values = row.ItemArray;
        ...
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM