Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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.

  • *Experts*
Posted

You can set a breakpoint at the top to step through and see which line has the problem. It's likely the following line, since you mentioned adding the Status column to the query:

   If drResults("Status") Then

 

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

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...