Question on rendering images from SQL database

  • Thread starter Thread starter Blasting Cap
  • Start date Start date
B

Blasting Cap

I am using the following code to pull an image out of a database &
display it on a web page.

Dim data As New data
Dim sID As String = Request.Params("itemID")
Dim sqlConnection As New SqlConnection(data.connectionString)
Dim sqlCom As New SqlCommand("Select Data, Type From tblImageStorage
Where (Story_ID='" & sID & "')", sqlConnection)
Dim sqlDataReader As SqlDataReader
sqlConnection.Open()
sqlDataReader = sqlCom.ExecuteReader
sqlDataReader.Read()
Dim byteArray As Byte() = CType(sqlDataReader("Data"), Byte())
Dim mstream As System.IO.MemoryStream = New
System.IO.MemoryStream(byteArray, 0, byteArray.Length)
Dim dbImage As System.Drawing.Image =
System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArray))
Dim bmp As Bitmap = New Bitmap(dbImage)
Dim scale As Single = 300.0F / System.Math.Max(0, bmp.Width)
Dim thumbnailImage As System.Drawing.Image =
bmp.GetThumbnailImage(CType((bmp.Width * scale), Integer),
CType((bmp.Height * scale), Integer), Nothing, System.IntPtr.Zero)
thumbnailImage.Save(Context.Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
sqlConnection.Close()


It works fine & displays the image fine.

However, the application I have needs to have the ability to read a
story out of the same sql database & display it. It seems that I can
only do one thing.

How can you display the graphic read from a SQL database AND the story
associated with it on the same page?

As an added "oddity" I have noticed that on the rendered page, that
"View Source" is not available from the file/edit/view menu. Do not
know if that means anything or not.

Any help appreciated.

BC
 
you only get one item per response. if you to return text and an image (at
least with IE), you need to return html with a image tag with a reference to
the image url.if you google this newgroup for sqlserver image, you will get
details.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top