Tech and a few other things RSS 2.0
# Tuesday, July 13, 2010




Error Readout:
System.IndexOutOfRangeException:

Fix:
I encountered the above error when I tried to run the query,
SELECT MAX(expression )
FROM tables
WHERE predicates;

and then loop through the results using a datareader with code like this,

while(rdr.Read())
{
someLabel.Items.Add(rdr["ColumnName"].ToString());
}
I got the error above, because when you do a "max" sql query it doesn't return any column header.

All you need to do is give the sql result set a column header.

SELECT MAX(expression) as "ColumnName" 
FROM
table
where predicates;

Explanation:
This is another one of my bone head mistakes. It's such a simple little thing I overlook, and gets me so disappointed in myself when I realize I spent time trying to figure this out. It's generally followed by me looking over my shoulder and seeing if any of my peers saw it. I'm mostly blogging this in hopes I won't make a silly mistake like this again.

Why is it always the baby errors that hang me up the most? It can never be something deep in the CLR, or possibly find a mistake in .Net. Nope, noway, not gonna happen .Net is pretty solid...for the most part.

Tuesday, July 13, 2010 10:14:10 PM (Central Standard Time, UTC-06:00)  #    Comments [0] - Trackback
.Net | SQL
Navigation
About the author/Disclaimer
        
My name is Ben Coffman. I'm in love with all things Mac yet I make a living in .NET. I view this as well rounded. When I turn the internet off I focus on family, random hobbies, and sharing moments in life.

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Ben Coffman

Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
All Content © 2010,

Sign In