What is wrong with this null check for data reader
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-14T10:13:56Z
Indexed on
2010/04/14
10:23 UTC
Read the original article
Hit count: 284
c.Open()
r = x.ExecuteReader
If Not r("filename").IsDbnull Then
imagepath = "<img src='images/'" & getimage(r("filename")) & " border='0' align='absmiddle'"
End If
c.Close()
r.Close()
I have also tried;
If r("filename") Is DBNull.Value Then
imagepath = String.Empty
Else
imagepath = "<img src='images/'" & getimage(r("filename")) & " border='0' align='absmiddle'"
End If
c.Close()
r.Close()
The error is: Invalid attempt to read when no data is present.
The idea of my code is to build an img src string only when data is available.
Help greatly appreciated.
Thanks
© Stack Overflow or respective owner