如何遍历数据集的特定列 [英] how to iterate through a particular column of a data set

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

问题描述

如何遍历数据集的特定列?





假设我在数据集中有四列。



我将如何仅在第二列中进行迭代。



column1 colum2 column3



1 ANU 23



2 ABHI 44



3 MUKESH 34



4 ANU 23





i希望迭代第二列......如果我再次找到这样的ANU ......我会将最后一个ANU追加到澳大利亚国立大学。[a包括点]



我该怎么做?

how to iterate through a particular column of a data set ?


suppose i have four columns in dataset.

How will i iterate through only in 2nd column.

column1 colum2 column3

1 ANU 23

2 ABHI 44

3 MUKESH 34

4 ANU 23


i want to iterate through 2nd column...if i find like here ANU again.... i will append the last ANU to ANU.[a dot is inluded]

how can i do that?

推荐答案

你不能遍历DataSet的列 - 它没有列。它是DataTables的集合,但它确实有列。因此,选择要查看它们的表:

You can't iterate through the columns of a DataSet - it doesn't have columns. It's a collection of DataTables which do have columns however. So pick the Table you want to look at an them:
DataTable dt = myDataSet.Tables[0];
foreach (DataRow row in dt.Rows)
    {
    Console.WriteLine(row[1]);
    // Or:
    Console.WriteLine(row["Column2"];
    }


这篇关于如何遍历数据集的特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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