通过数据集迭代 [英] Iterate through DataSet

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

问题描述

我有一个的DataSet 名为数据集1 。它包含表的一个未知的数量和这些表中的数目不详的列和行。我想通过每个表圈,并期待在所有数据中的每一行每一列英寸我不知道如何代码这一点。任何帮助,将不胜感激!


解决方案

 的foreach(在dataSet.Tables DataTable的表)
{
的foreach(DataRow的行table.Rows)
{
的foreach(在row.ItemArray对象的项目)
{
//读取项目
}
}
}

或者,如果你需要的列信息

 的foreach(在dataSet.Tables DataTable的表)
{
的foreach(DataRow的行表。行)
{
的foreach(在table.Columns的DataColumn列)
{
对象项目=行[专栏];
//读取列和项目
}
}
}


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
        }
    }
}

这篇关于通过数据集迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆