Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IndexOutOfRangeException

Status
Not open for further replies.

SteveL714

Programmer
Sep 19, 2013
21
0
0
US
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

 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top