[英]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.