谁知道如何用For Loop而不是foreach循环遍历Dataset中的所有数据表?
我知道foreach循环可以做到这一点,但是,我想用For循环代替.
例如:
foreach (DataTable table in ds.Tables)
{
} 我想用For循环代替.
如果有人能帮我做这件事很感激
发布于 2015-09-29 09:02:48
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
}发布于 2015-09-29 09:03:25
您可以使用ds.Tables.Count属性来完成以下操作:
for (int i = 0; i < ds.Tables.Count; i++)
{
// access your table with indexes:
Console.WriteLine(ds.Tables[i].ToString());
}发布于 2015-09-29 09:04:51
DataSet dsTemp = new DataSet();
for (int tableIndex = 0; tableIndex < dsTemp.Tables.Count; tableIndex++)
{
DataTable dtIndex = dsTemp.Tables[tableIndex];
//code here
}这样的话..。
https://stackoverflow.com/questions/32839873
复制相似问题