通过一个DataTable循环 [英] Looping through a DataTable

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

问题描述

嘛。我有多个列和多行的DataTable



我想通过数据表圈动态基本上输出应如下所示不含括号:

 名称(的DataColumn)
汤姆(DataRow中)
彼得(DataRow中)

姓(的DataColumn )
·史密斯(DataRow中)
布朗(DataRow中)

的foreach(在rightsTable.Columns的DataColumn COL)
{
的foreach(DataRow的行rightsTable。行)
{
//输出
}
}

我输入了这一点,并注意到这是行不通的。可有人请这个干什么?


解决方案

 的foreach(DataColumn的山坳更好的办法指教在rightsTable.Columns)
{
的foreach(DataRow的行rightsTable.Rows)
{
Console.WriteLine(行[col.ColumnName]的ToString());
}
}


Well. I have a DataTable with multiple columns and multiple rows.

I want to loop through the DataTable dynamically basically the output should look as follows excluding the braces :

Name (DataColumn)
Tom  (DataRow)
Peter (DataRow)

Surname (DataColumn)
Smith (DataRow)
Brown (DataRow)

foreach (DataColumn col in rightsTable.Columns)
{
     foreach (DataRow row in rightsTable.Rows)
     {
          //output              
     }
} 

I typed that out and noticed this would not work. Can someone please advice on a better way of doing this?

解决方案

foreach (DataColumn col in rightsTable.Columns)
{
     foreach (DataRow row in rightsTable.Rows)
     {
          Console.WriteLine(row[col.ColumnName].ToString());           
     }
} 

这篇关于通过一个DataTable循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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