Saturday, March 31, 2012

System.IndexOutOfRangeException

Hello,

I have the following code where all the used variable are declared to their respective types:

insertSql = "SELECT Max([Customer ID]) AS CustID FROM [Registration Info]"
objCommand = New OleDbCommand(insertSql, objConn)
objConn.Open()
objDR = objCommand.ExecuteReader()

While objDR.Read()
CustID=objDR("Cust ID") '********** (1.)
End While

I am getting an error on (1.). its says "System.IndexOutOfRangeException: Cust ID" why is this happening? Can comeone help me whith this problem?

Thanks,
~sIf the code enters the while loop then tere are values within objDR so why not add a watch to this and check the value of objDr(0) and then objDR(1)

Hope that helps

Cheers
Gregor Suttie
I would say it is happening because there is no field in the result called "Cust ID", though there is one called "CustID"
Yes i know thats a silly mistake on my part. very silly... i wish i could delete this post. :) thanks very much. now i am doing it like objDR(0)

Regards.

0 comments:

Post a Comment