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