Using sqldatareader in asp.net
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-14T08:42:34Z
Indexed on
2010/04/14
8:53 UTC
Read the original article
Hit count: 337
I have this code to get data;
s = "select documents.filename, documents.description, documents.filesize from documents, contentdocuments, content where contentdocuments.contentid = content.id and content.id = @contentid and contentdocuments.documentsid = documents.id ORDER BY documents.description"
x = New SqlCommand(s, c)
x.Parameters.Add("@contentid", SqlDbType.Int)
x.Parameters("@contentid").Value = contentid
c.Open()
r = x.ExecuteReader
If r.Read Then
DownloadsRepeater.DataSource = r
DownloadsRepeater.DataBind()
**imagepath = "<img src='images/'" & getimage(r("filename")) & " border='0'** align='absmiddle'"
End If
c.Close()
r.Close()
The problem is on the line;
imagepath = "<img src='images/'" & getimage(r("filename")) & "
The error is;
Invalid attempt to read when no data is present.
How can I check to make sure data is present and get rid of this error? I thought the 'if r.read' did this?
Thanks
:EDIT:
Function getimage(ByVal strin As String) As String
If strin > "" Then
dotpos = InStrRev(strin, ".")
ext = Right(strin, Len(strin) - dotpos)
getimage = ext & ".gif"
End If
Return getimage
End Function
© Stack Overflow or respective owner