Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

 

I am trying to display images that are stored in the database on my web page. From what I have read, I should get the images and display them on one page, and then link my image control to the page i.e.

Photo.aspx would contain the code for downloading and displaying my image.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       Try
           OpenConnection()
           sqlCmd = New SqlCommand
           sqlCmd.Connection = conSql
           sqlCmd.CommandText = "SELECT Picture, ImageType FROM myImages WHERE Identification = " & Request.QueryString("ID").ToString
           Dim myDataReader As SqlDataReader
           myDataReader = sqlCmd.ExecuteReader
           Do While (myDataReader.Read())
               Response.ContentType = myDataReader.Item("ImageType")
               Response.BinaryWrite(myDataReader.Item("Picture"))
           Loop
           myDataReader.Close()
           Response.Redirect("default.aspx", False)
       Catch ex As Exception
       Finally
           CloseConnection()
       End Try
   End Sub

 

While the page default.aspx would have an image control imgPicture, whose imageUrl is set to the page Photo.aspx. The only problem is that I cannot get/don't know how to get the page_load event to execute.

 

Mike55

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Ok, after a lot of cursing and swearing at the computer and the world in general, I sorted out a solution. On the default.aspx add an html Image control, set its runat property to "server", set the id and name property to "image2" (you can use anything you like). In your code, when you want to display a picture for a particular person, call the following line of code:

image2.src = "photo.aspx?id=" & me.txtImage.text

where txtImage is a text box where you specify the id number of the picture you wish to display.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...