문제

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()

도움이 되었습니까?

해결책

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")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top