使用 For 循环遍历 DataSet 中的所有 DataTable

Loop Through All DataTable in DataSet Using A For Loop

有人知道如何使用 For Loop 而不是 foreach 循环遍历 Dataset 中的所有数据表吗?

我知道 foreach 循环可以做到这一点,但我想改用 For 循环。

例如:

foreach (DataTable table in ds.Tables)
{

}   

我想改用 For 循环。

如果有人可以帮助我,我将不胜感激

DataSet  dt = new DataSet();
//Populate dataset here
//Iterate throuh datatables inside the dataset
for(int i=0;i<dt.Tables.Count;i++)
    {
      DataTable temptable = dt.Tables[i]; // this will give you the datatable in each iteration level
        //Do your doce here
    }

您可以使用 ds.Tables.Count 属性 来执行此操作:

 for (int i = 0; i < ds.Tables.Count; i++)
 {
     // access your table with indexes:
     Console.WriteLine(ds.Tables[i].ToString());
 }
DataSet dsTemp = new DataSet();
for (int tableIndex = 0; tableIndex < dsTemp.Tables.Count; tableIndex++)
{
    DataTable dtIndex = dsTemp.Tables[tableIndex];
    //code here
}

这样...