System.IndexOutOfRangeException

mfriedenthal

New member
Joined
Aug 18, 2005
Messages
2
I have a VB.net app that stores data on SQL. I added a new field called "Status" to one of the SQL tables, of type bit, and created stored procedures to retrieve and edit the new field.

Everything works perfectly when the app is compiled in Debug mode.

However, when it is compiled in Release mode I get the following error:

System.IndexOutOfRangeException: Status

The code is executed OnLoad:

Code:
Try
            MyAppConnection.Open()
            MyAppSQLCommand.Connection = MyAppConnection
            drResults = MyAppSQLCommand.ExecuteReader
            While drResults.Read
                If drResults("Status") Then
                    Status = "Active"
                Else
                    Status = "Not Active"
                End If
                liIndex = New ListItem(drResults("Name").ToString() & " - " & Status, drResults("I_ID").ToString)
                ddlInspectors().Items.Add(liIndex)
            End While
            drResults.Close()
        Catch ex As Exception
            RecordError(ex.ToString)
        Finally...

The stack looks like:

System.IndexOutOfRangeException: Status
at System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at System.Data.SqlClient.SqlDataReader.get_Item(String name)
at MyApp.Utilities.MyMethod()


Can anyone suggest a solution, or at least, how to go about tracking down the source of the error?

Thank you.
 
You can set a breakpoint at the top to step through and see which line has the problem. Its likely the following line, since you mentioned adding the Status column to the query:
Code:
    If drResults("Status") Then

The error line "System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)" is saying that its trying to find a column by name and cant find it. That means the code certainly thinks a column isnt there. Id check that you really are getting back the Status column (run the query directly through whatever tool you use).

-ner
 
Back
Top