Saturday, March 31, 2012

System.IndexOutOfRangeException

I'm seeing the above error message appear on a web form. All the formcode-behind does is grab data from a SQL Server db (2005 Beta) andwrite it out in specfied controls.
The line that throws up the error is the following:
<code>
Line 150: txtCoDeath1a.Text = dtr("COD1a")
</code>
'Dtr' is simply a datareader that has been initialised previously. Iknow I should be checking for nulls in the db, but that isn't theproblem in this instant as the record I'm grabbing does have data forthe field 'COD1a'. It's of type nvarchar, length 150.
I've googled this error and have not found anything that seems directly relevant.
I'm using VB.
Any help much appreciated.

try putting this before your code

if dtr.Read then
dtr("COD1a")
end if


Sorry Chris, I should've posted more of my code.
I already have those lines in the code.
Any other ideas?

Try this

if not System.DBNull(dtr("COD1a")) then

txtCoDeath1a.Text = dtr("COD1a")

end if

Could you post more of your code? Are results coming back from the database? Is there a field called COD1a?


Thanks for the help guys, but I've located the source of theproblem. Very simple; I'd misnamed 'Cod1a'. Its actually 'CodIa'. Spotthe difference? Neither did I for a while!
<Sheepish> Sorry and thanks again.

0 comments:

Post a Comment