如何遍历DataTable中在给定行中的所有项目 [英] How to iterate all items in a given row in the DataTable

查看:432
本文介绍了如何遍历DataTable中在给定行中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何迭代中的 DataTable中所有的项目在给定行。我有以下的code遍历所有的行,我想另外一个for循环迭代的所有单元格在给定行?

How to iterate all items in a given row in the DataTable . I have the following code to iterate all rows, I want another For loop to iterate all cells in a given row ?

For Each row As DataRow In dt.Rows

Next row

我可以访问每一行,但我想在该行访问的每个列,因为我不知道名字和列的计数,..

I can access each row, but I want to access each column on the row, as I don't know the name and the count of the columns ,..

推荐答案

您已经通过循环<一个href=\"http://msdn.microsoft.com/en-us/library/system.data.datarow.itemarray.aspx?cs-save-lang=1&cs-lang=vb#$c$c-snippet-2\">DataRow.ItemArray.在 C#,我们可以做到以下code:

You have to loop through DataRow.ItemArray. In C#, we can do it by following code:

 foreach (DataRow dr in dt.Rows)
   {
     foreach (var item in dr.ItemArray)
       {
                Console.WriteLine(item);
       }
   }

这是等同于以下VB.NET code。

This is equivalent to the following VB.NET code.

For Each dr As DataRow In dt.Rows
    For Each item In dr.ItemArray
        Console.WriteLine(item)
    Next
Next

这篇关于如何遍历DataTable中在给定行中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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