遍历数据集遍历、数据

2023-09-06 04:43:45 作者:棉花糖味的小仙女

我有一个名为 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
        }
    }
}