[英]Getting specific row item from a datatable
我有一个数据表。 让我们称之为dt。 它具有三列。 id,link_id和值。 我在for each循环中遍历数据表中的每个结果。
For Each Row As DataRow In dt.Rows
Try
'do whatever
Catch Ex As Exception
End Try
在我做的任何事情上 ,我将如何仅获取当前行的值并将其分配给变量?
如果您使用的是通用DataTable
请尝试以下操作:
For Each Row As DataRow In dt.Rows
Try
'Show all 3 fields/columns
Console.WriteLine Row.Item(0) & " - " & Row.Item(1) & " - " & Row.Item(2)
Catch Ex As Exception
End Try
Next
如果您使用的是强类型DataTable
请尝试以下操作:
For Each Row As StronglyTypedDataRow In dt.Rows
Try
'Show all 3 fields/columns
Console.WriteLine Row.id & " - " & Row.link_id & " - " & Row.Value
Catch Ex As Exception
End Try
Next
您可以尝试关注。
For Each Row As DataRow In dt.Rows
Try
var linkId = row("link_id")
Catch Ex As Exception
End Try
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.