I don't know if my way is conventional. Here is what I do.
The page that requests an image uses as session variable to hold the
primary key information for the record I am looking for. This page also
has an img tag bound to a 2nd page that will load the picture. I check
to see if there is picture data, and if there is, I make the img tag
visible that is bound to the page showing the picture. I'm not very
experienced with this stuff, but I was able to get it to work this way.
So again,
1) user click a data grid in order to see a picture.
2) I pass the primary key for that record based on previous click to
session
3) I check to see if picture data is there and show the img tag bound
to a 2nd page that will output the picture based on the session
variable.
here is my img tag:
<img id ="img_email_picture_lenel" src="picture_lenel.aspx"
height="300" width="250" runat="server">
Here is my datagrid code:
If e.commandname="picture" Then
Dim cmd_load_picture As SqlCommand
Dim dtr_load_picture As SqlDataReader
'Dim str_blob_length As String
cmd_load_picture = New SqlCommand ("SELECT * FROM mmobjs WHERE
empid='" & session("empid") & "'", conMatt_I3)
dtr_load_picture = cmd_load_picture.ExecuteReader()
If dtr_load_picture.read() = false Then
div_person_lookup_no_picture.visible = true 'shows alert div
stating no photo available
img_person_lookup_lenel.visible = false 'hides lenel picture
because there isn't one
img_person_lookup_none.visible = true 'shows image for no photo
available
Else
div_person_lookup_no_picture.visible = false 'hides alert div
stating no photo available
img_person_lookup_lenel.visible = true ' show lenel picture
img_person_lookup_none.visible = false 'hide no photo picture
'Response.Write("<Script
language='javascript'>window.open('picture.aspx',n ull,'height=300,
width=300, status= no, resizable= no, scrollbars=yes,
toolbar=no,location=no,menubar=no, left=900, top=100 ');" & chr(60) &
"/script>")
End If
End If
Here is the page showing the picture:
Sub Page_Load
conMatt_I3.Open()
Dim cmdLoadAttachment As SqlCommand
Dim dtrLoadAttachment As SqlDataReader
'Dim str_blob_length As String
cmdLoadAttachment = New SqlCommand ("SELECT * FROM mmobjs WHERE
empid='" & session("empid") & "'", conMatt_I3)
dtrLoadAttachment = cmdLoadAttachment.ExecuteReader()
dtrLoadAttachment.Read()
Response.Buffer = True
Response.ContentType = "Image/BMP"
Response.BinaryWrite(dtrLoadAttachment("lnl_blob") )
dtrLoadAttachment.Close()
Hope this helps you.
End Sub
B wrote:
Matt,
You specify in one of your posts that you already retreive your images from
the SQL DB. Could you post an example or send it to me on how to do that?
I can upload images into my SQL DB, but can't retreive them in a GridView or
DetailsView. I'm using ASP.NET 2.0 and VB.NET.
Thanks for your help,
Bart
"ma******@bellsouth.net" wrote:
Thanks rviray,
The database are on two different server and I do not have control
(just read access) where the image is coming from. I tried using
viewstate to transfer information with not luck. I tried a byte array
but I dont think I read the length correctly. I will try the session
and get back to you. I would need to see code for the byte aray because
I am doing something wrong. Simple version of my code below ( I am
purposely leaving the database configurations out):
Dim my_byt_variable As Byte()
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)
the above format doesn't work for me. I think have to redim the byte
variable with the length of the datareader data
Dim my_byt_variable As Byte()
ReDim bytContent(my_data_reader("my_image").length)
my_byt_variable = my_data_reader("my_image")
INSERT INTO my_table (image) VALUES (my_byt_variable)
but I don't think this worked for me either. It has been a week since I
have played with it. Need to get back to it I guess. Thanks for your
help.