从数据表中获取特定的行项目
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
在我的 do whatever 位中,我如何只获取当前行的 value 并将其分配给变量?
如果您使用的是通用 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
我有一个数据表。让我们称之为 dt。它有三列。 id、link_id 和值。 我正在使用 for each 循环遍历数据表中的每个结果。
For Each Row As DataRow In dt.Rows
Try
'do whatever
Catch Ex As Exception
End Try
在我的 do whatever 位中,我如何只获取当前行的 value 并将其分配给变量?
如果您使用的是通用 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