Solved

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

Posted on 2008-06-09
3
155 Views
Last Modified: 2010-04-23
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

0
Comment
Question by:isischen
  • 2
3 Comments
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21748510
try this...

autoreader.fields(0).value

Regards,
M.Raja
0
 
LVL 14

Accepted Solution

by:
rachitkohli earned 500 total points
ID: 21748715
myrow(mycol) = autoreader.Item("ColumnName")
0
 
LVL 14

Expert Comment

by:raja_ind82
ID: 21749024
rachitkohli  is correct.  sorry,  my answer is working only in VB.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question