mike55 Posted November 2, 2006 Posted November 2, 2006 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 Quote 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)
mike55 Posted November 2, 2006 Author Posted November 2, 2006 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. Quote 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)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.