datarow by column name
19,189
Exactly like you wrote it:
dr(i)("column_name").ToString()
MSDN reference:
For strongly typed value of other types (for example, Integer, you could use Field(Of T)
extension):
In your case,
dr(i).Field(Of String)("column_name")
Author by
user1164545
Updated on June 09, 2022Comments
-
user1164545 almost 2 years
I am using this code:
Dim dr() As DataRow = datatable.Select("id='" & st) For i = 0 To dr.GetUpperBound(0) result = dr(i)(2).ToString() Next i
How do I get result by column name instead of
dr(i)(2)
? Because if I add a column to that data table in front, then I get the wrong data, I should usedr(i)(3)
. So I want to overcome this without changing source code in the future. Something likedr(i)("column_name").ToString()
-
Tim Schmelter about 10 yearsIndices are zero based in .NET.
-