title: ADO.Net Not Recognizing Column in Select Statement
body: <p>I have a query that executes fine in TOAD, but when bringing back the results with either an ADO.Net DataReader or DataAdapter/DataSet, it's not recognizing a column in the select statement.  See the query below... the column in question has its data coming from a dynamic table or sub-select or whatever you call it.  I don't see why this is a problem in .Net:</p>
  
  <pre><code>Dim sql As String = String.Format("select bu.row_id, bu.name, selectedOrgs.bu_id as selectedOrg " _
                  &amp; " FROM SIEBEL.s_prod_int_bu pb " _
                  &amp; " INNER JOIN SIEBEL.s_bu bu on pb.bu_id = bu.row_id " _
                  &amp; " LEFT OUTER JOIN (select bu_id " _
                         &amp; " FROM SIEBEL.s_lit_bu " _
                         &amp; " WHERE lit_id = ?) selectedOrgs on selectedOrgs.bu_id = bu.row_id " _
                  &amp; " WHERE pb.prod_int_id in ('{0}') " _
                  &amp; " ORDER BY bu.name ", String.Join("','", ids.ToArray()))
  
              'We also need to add a parameter
              cmd.Parameters.AddWithValue("", resourceID)
  </code></pre>
  
  <p>I have an OdbcCommand object "cmd" and an OdbcDataReader "dr".  I'm initializing the ObcDataReader as I always do: dr = cmd.ExecuteReader().  But in the loop through the records (see below), the code blows up on retrieving the "selectedOrg" column from the SQL above (Index out of range exception):</p>
  
  <pre><code>        dr = cmd.ExecuteReader
          If dr.HasRows Then
              While dr.Read
                  Dim bu As New OrgResource
                  'Dim bu As New Resource
                  bu.ID = IIf(IsDBNull(dr.Item("row_id")), "", dr.Item("row_id"))
                  bu.Name = IIf(IsDBNull(dr.Item("name")), "", dr.Item("name"))
                  bu.Selected = False
                  If Not String.IsNullOrEmpty(resourceID) Then
          'BOOM: Code blows up on next line
                      bu.Selected = Not IsDBNull(dr.Item("selectedOrg"))
                  End If
                  lRet.Add(bu)
              End While
          End If
  </code></pre>
  
  <p>I don't think that this should blow up as the SQL is returning correctly in TOAD, and .Net should see this column as a normal column, right?  I tried swapping the OdbcDataReader out with an OdbcDataAdapter/DataSet combo, and it blows up in the same area.  In fact, in Studio's Watch window, if I do: ds.Tables(0).Columns.Count, it shows that I only have 2 columns.  (In Jerry Seinfeld voice: What's the deal with that?)</p>
  
  <p>Exception Details with stack trace info:</p>
  
  <p>System.IndexOutOfRangeException
  InnerException: Nothing
  Message: selectedOrg
  Source: System.Data
  StackTrace:    at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
     at System.Data.Odbc.OdbcDataReader.GetOrdinal(String value)
     at System.Data.Odbc.OdbcDataReader.get_Item(String value)
     at MyNameSpace1.MyProject.MyClass.MyMethod(List`1 ids, String resourceID) in 
  C:\Documents and Settings\my_username\My Documents\MyProject\MyClass.vb:line 1088</p>
  
  <p>Thanks for your help!!</p>
  
  <p>Andy</p>