使用For循环遍历DataSet中的所有DataTable [英] Loop Through All DataTable in DataSet Using A For Loop

查看:663
本文介绍了使用For循环遍历DataSet中的所有DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何使用For循环而不是foreach循环遍历数据集中的所有数据表?我知道foreach循环可以做到这一点,但我想使用For循环。



例如:



does anyone know how do I loop through all datatable in dataset with a For Loop instead of foreach loop? I know foreach loop can do this but I want to use a For loop instead.

For example:

foreach (DataTable table in ds.Tables)
{
}





我想使用For循环。



感谢有人可以帮我解决这个问题。谢谢!



问候,



Felicia



I would like to use a For Loop instead.

Appreciate if someone can help me on this. Thanks !

Regards,

Felicia

推荐答案

你可以这样做:



You can do:

DataSet ds = new DataSet();
for (int count = 0; count < ds.Tables.Count; count++)
{
    // Get individual datatables here...
    DataTable table = ds.Tables[count];
}


只需使用 Dataset.Tables.Count 属性



By simply using Dataset.Tables.Count property

for (int i=0; i< ds.Tables.Count;i++)
{
   //your logic goes here
}





你为什么不想使用foreach,任何具体原因?

除非有任何特殊要求,否则我建议使用foreach for for循环。



希望,它有助于:)



Why don't you want to use foreach, any specific reason?
I would like to recommend to use foreach over for loop unless there is any specific requirement.

Hope, it helps :)


for(int i=0; i < ds.Tables.Count; i++)
{
    // TODO:...
}





-KR



-KR


这篇关于使用For循环遍历DataSet中的所有DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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