How to fix Index out of range exception on idatareader
- by Phil
Good morning stack overflow,
I have been forced into using the idatareader as opposed to the sqldatareader which has .hasrows available.
In my code I am attempting to handle nulls like this:
reader = GetContent(pageid)
While reader.Read
If reader("content") IsNot DBNull.Value Then
content = Replace(reader("content"), Chr(38) + Chr(97) + Chr(109) + Chr(112) + Chr(59) + Chr(98) + Chr(104) + Chr(99) + Chr(112) + Chr(61) + Chr(49), "")
If reader("id") IsNot DBNull.Value Then
contentid = reader("id")
End If
Else
contentid = -1
content = String.Empty
End If
End While
Outputcontent.Text = content
I am getting an 'Index Out of Range Exception' here:
If reader("content") IsNot DBNull.Value Then
The database does 100% contain 'content'