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")
Share:
19,189
user1164545
Author by

user1164545

Updated on June 09, 2022

Comments

  • user1164545
    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 use dr(i)(3). So I want to overcome this without changing source code in the future. Something like dr(i)("column_name").ToString()

    • Tim Schmelter
      Tim Schmelter about 10 years
      Indices are zero based in .NET.