INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

IndexOutOfRangeException

IndexOutOfRangeException

(OP)
In my C# application I've retrieved a row of data from a MS-Sql database. While the majority of the data is coming across fine, the data reader in C# is throwing the "IndexOutOfRangeException" message on three columns in the result set. Those columns are defined in SQL as nvarchar(128). One of the columns (SecurityAnswer) contains the following value: 50D8B4A941C26B89482C94AB324B5A274F9CED66

Here's an extract of the code that is failing:

CODE

String cSecurityAnswer;
cSecurityAnswer = myReader["SecurityAnswer"].ToString(); 

What do I need to do in order to be able to read the data from the Sql table in my C# code?

Steve

RE: IndexOutOfRangeException

Hi Steve,

post your query string, please. And some more of your code. Do you check if(myReader.HasRows())?

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: IndexOutOfRangeException

What is myReader declared as? If it is a SqlDataReader object, you might be looking to use the GetString(n) method to get the nth (0 based) field as a string.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close