none
IDataReader .GetOrdinal throws exception IndexOutOfRange, SQL coloumn names RRS feed

  • Question

  •  

    Hi Guys

     

    I have a C# method calling a stored procedure.

    I am then using an IDataReader to get the values in each column.

    However the IndexOutOfRange exception is thrown is I use .getOrdinal and the name.

    If I provide the column as an iteger it works.

    The column name is correct and I have tried numerous ways of checking it.

    I have since discoved that the error is thrown when its getting columns my stored procedure provides.

     

    As an example,

     

    ISNULL(TableAlias.ReferenceCode, '') AS 'ReferenceCode'

     

    will cause an error but columns not provided using AS pass ok.

     

    Looking around many people seem to be having different variations of this problem, and no one seems to have found a solution. Could people experiancing this problem please check if your sql uses the above layout.

     

    If anyone has any ideas / things to add please do!

     

    Many Thanks,

    Michael

    Friday, August 8, 2008 11:12 AM

Answers

  • Problem solved.

     

    The IDataReader is a forward only reader and I had my stored procedure giving back columns that I was then browsing up and down trying to find the column names.

     

    Small details aways seem to cause the biggest problems!

     

    Thank you for your time.

     

    Regards,

    Michael

    Tuesday, August 12, 2008 9:55 AM

All replies

  • Hi Michael

     

    In order to help, we need more details:

    * .Net version

    * client OS version

    * SQL server details (which SQL server you are using, which version)

    * which provider you are using (is it SqlDataReader, ODBC, OleDB, Oracle)

    * code and stored procedude snippets, when possible - remember to override sensitive info with simple words. But, try keeping non-English characters in names, if you are using them.

     

    Regards,

     Nissim

    Sunday, August 10, 2008 5:23 PM
    Moderator
  • Hi,

     

    Thank you for replying.

    I am using .NET 3.5

    Windows XP Professional SP3 fully updated

    Visual Studio 2008 Team Developer Edition

    SQL server 2005 enterprise edition fully patched

    I am using Enterprise Library 4.0 (May 2008)

    im just using System.Data.IDataReader which points to a database.executeReader("command")

    I will post a code sample shortly of the stored procedure and the c# code. (Within 2 hours)

     

    Many Thanks,

    Michael

     

     

    Monday, August 11, 2008 5:39 PM
  • Problem solved.

     

    The IDataReader is a forward only reader and I had my stored procedure giving back columns that I was then browsing up and down trying to find the column names.

     

    Small details aways seem to cause the biggest problems!

     

    Thank you for your time.

     

    Regards,

    Michael

    Tuesday, August 12, 2008 9:55 AM
  • The IDataReader is a forward only reader and I had my stored procedure giving back columns that I was then browsing up and down trying to find the column names.

    Michael , can you be more specific on this statement plz ? i've not followed when you say , "i had my stored procedure giving...."

    I've exactly similar issue & have not figured out whats happening. column names are correct and interestingly it happens only one user !

    Thanks for the advise.

    prk
    Sunday, September 6, 2009 11:50 PM
  • Mmm, I'm curious too...
    Thursday, June 16, 2011 11:38 AM