[英]Loop through the rows of a particular DataTable
IDE: VS 2008, Platform: .NET 3.5, IDE:VS 2008,平台:.NET 3.5,
Hi,你好,
Here is my DataTable columns:这是我的 DataTable 列:
ID Note Detail身份证件详情
I want to write sth like this:我想这样写:
//below code block is not the right syntax
For each q in dtDataTable.Column("Detail")
strDetail = Row of Column Detail
Next
Can anyone give me a suggestion and show me a code sample please?任何人都可以给我一个建议并给我看一个代码示例吗? Thanks.谢谢。
For Each row As DataRow In dtDataTable.Rows
strDetail = row.Item("Detail")
Next row
There's also a shorthand:还有一个简写:
For Each row As DataRow In dtDataTable.Rows
strDetail = row("Detail")
Next row
Note that Microsoft's style guidelines for.Net now specifically recommend against using hungarian type prefixes for variables.请注意,Microsoft 的 .Net 样式指南现在特别建议不要对变量使用匈牙利类型前缀。 Instead of "strDetail", for example, you should just use "Detail".例如,您应该只使用“Detail”而不是“strDetail”。
Dim row As DataRow
For Each row In dtDataTable.Rows
Dim strDetail As String
strDetail = row("Detail")
Console.WriteLine("Processing Detail {0}", strDetail)
Next row
Here's the best way I found:这是我发现的最好方法:
For Each row As DataRow In your_table.Rows
For Each cell As String In row.ItemArray
'do what you want!
Next
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.