I couldn't get the value of a column at a specific ordinal from a datareader.

Something worked for me the last time around ---  myrow(mycold1) = autoreader.GetValue(2)
but now, it,autoreader.getvalue(2), only return the column name.  
What I want is the content of the datareader's column returned from a datareader.read() method.
If I try to use datareader.getstring(2), I got a 'cast' exception.

Using autoreader As System.Data.OleDb.OleDbDataReader = selectCmd.ExecuteReader()
                        autoreader.Read()
                        myrow = _DtText.NewRow()
                        myrow(mycol) = autoreader.GetValue(2)

Open in new window

isischenAsked:
Who is Participating?
 
rachitkohliConnect With a Mentor Commented:
myrow(mycol) = autoreader.Item("ColumnName")
0
 
raja_ind82Commented:
try this...

autoreader.fields(0).value

Regards,
M.Raja
0
 
raja_ind82Commented:
rachitkohli  is correct.  sorry,  my answer is working only in VB.
0
All Courses

From novice to tech pro — start learning today.