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

Re: Reader ordinal problem by Scott

Scott
Sun Jan 21 15:25:24 CST 2007

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" <John@nospam.infovis.co.uk> wrote in message
news:OzpeTnZPHHA.4484@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
>
>



Re: Reader ordinal problem by Jay

Jay
Sun Jan 21 17:49:41 CST 2007

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" <John@nospam.infovis.co.uk> wrote in message
news:OzpeTnZPHHA.4484@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
>
>


Re: Reader ordinal problem by Miha

Miha
Mon Jan 22 04:09:33 CST 2007


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@tsbradley.net> wrote in
message news:u2NyTbbPHHA.1604@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/