遍历数据集

Iterate through DataSet(遍历数据集)

本文介绍了遍历数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 DataSet1DataSet.它包含未知数量的表以及这些表中未知数量的列和行.我想遍历每个表并查看每一行中每一列的所有数据.我不确定如何编码.任何帮助将不胜感激!

I have a DataSet named DataSet1. 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
        }
    }
}

这篇关于遍历数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:遍历数据集

基础教程推荐