473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Reader ordinal problem

Hi

I am getting the System.IndexOutOfRangeException was unhandled error on the
last line of below code;

Cmd = New OleDb.OleDbCommand("SELECT [Last Staff Update From Site] FROM
[Update Control]", LocalConn)
Reader = Cmd.ExecuteReader()
Console.WriteLine("{0}", Reader.GetOrdinal("[Last Staff Update From Site]"))

What is the problem and how can I fix it?

Thanks

Regards
Jan 21 '07 #1
3 1566
A DataReader is initialized so that it is pointing just BEFORE the first
record returned by your query. As such, you aren't pointing to any data
when you attempt to get the ordinal in question.

You must advance the reader to the first record before querying it:

Cmd = New OleDb.OleDbCommand("SELECT [Last Staff Update From Site] FROM
[Update Control]", LocalConn)
Reader = Cmd.ExecuteReader()

Do While Reader.Read()
Console.WriteLine("{0}", Reader.GetOrdinal("[Last Staff Update From
Site]"))
Loop
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:Oz**************@TK2MSFTNGP02.phx.gbl...
Hi

I am getting the System.IndexOutOfRangeException was unhandled error on
the last line of below code;

Cmd = New OleDb.OleDbCommand("SELECT [Last Staff Update From Site] FROM
[Update Control]", LocalConn)
Reader = Cmd.ExecuteReader()
Console.WriteLine("{0}", Reader.GetOrdinal("[Last Staff Update From
Site]"))

What is the problem and how can I fix it?

Thanks

Regards


Jan 21 '07 #2
John,
Have you tried:
Console.WriteLine("{0}", Reader.GetOrdinal("Last Staff Update From Site"))
Generally this is why I avoid including spaces in field names...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:Oz**************@TK2MSFTNGP02.phx.gbl...
Hi

I am getting the System.IndexOutOfRangeException was unhandled error on
the last line of below code;

Cmd = New OleDb.OleDbCommand("SELECT [Last Staff Update From Site] FROM
[Update Control]", LocalConn)
Reader = Cmd.ExecuteReader()
Console.WriteLine("{0}", Reader.GetOrdinal("[Last Staff Update From
Site]"))

What is the problem and how can I fix it?

Thanks

Regards

Jan 21 '07 #3

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
message news:u2**************@TK2MSFTNGP05.phx.gbl...
John,
Have you tried:
>Console.WriteLine("{0}", Reader.GetOrdinal("Last Staff Update From
Site"))

Generally this is why I avoid including spaces in field names...
Oh yes, having columns with blanks is really a bad idea.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jan 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: stewartfip | last post by:
How do I get the ordinal of a form element from a reference to the object itself. For example: <html> <script language="javascript"> function disp_val(objField){ alert(---the ordinal of...
4
by: Mark Tarver | last post by:
Prompted by a post on Catalan numbers in Qilang, I got into looking at ordinal numbers as defined by John von Neumann - see http://en.wikipedia.org/wiki/Ordinal_numbers 0 = {} 1 = {0} = {{}} 2...
4
by: yhebib | last post by:
Hello All, I've been browsing and reading all articles I could find on technet ,msdn and other knowledgeable sources to understand the issue I'm dealing with. However, I did not find so far how...
7
by: Dylan Parry | last post by:
Hi folks, I was wondering if there is any way of formatting a date to include the ordinal characters? I've looked at the documentation for DateTime.ToString(), but no where can I find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.