how to Retrive Image in Data Base(Sql Server2000)
ASP.Net Problem
Collapse
X
-
Tags: None
-
This article will answer your questionOriginally posted by Puneet Guptahow to Retrive Image in Data Base(Sql Server2000) -
below code is used to show image from database but u have give page as url to image tag with proper image id
<img src="showImage. aspx?imageid=12 1" />
--------- showImage.aspx
[code=vbnet]
<%@ Page Language="vb" AutoEventWireup ="false" %>
<%@import Namespace=Syste m.IO %>
<%@Import namespace=Syste m.Data.SqlClien t %>
<%@Import namespace= System.Threadin g %>
<%@Import namespace= System %>
<%@Import namespace= System.Data %>
<%@Import namespace= System.Web %>
<%@ Import Namespace="Syst em.Drawing" %>
<%@Import namespace= System.Drawing. Bitmap %>
<%@ Import Namespace="Syst em.Configuratio n" %>
<%@ Import Namespace="Syst em.Drawing.Imag ing" %>
<%@Import namespace= System.Web.UI.W ebControls.Imag e %>
<script runat="server">
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
</script>
<%
con = New SqlConnection(C onfigurationMan ager.Connection Strings("deskto pConnectionStri ng").Connection String.ToString ())
con.Open()
Dim ret_img As String
ret_img = "SELECT B.TITLE, B.IMAGEPATH FROM SESSION where IMAGE_ID='" + Request.QuerySt ring("imageid") + "' "
' ret_img = "select Image_Data from InterScope.GROS S_IMAGE_STORE where IMAGE_ID='40' "
cmd = New SqlCommand(ret_ img, con)
dr = cmd.ExecuteRead er
Dim imagedata As Byte()
Dim bmp As Bitmap
If dr.HasRows Then
dr.Read()
imagedata = dr.Item(0)
' Response.Buffer = True
If imagedata.Lengt h > 0 Then
Dim srm As MemoryStream = New MemoryStream(im agedata, True)
srm.Write(image data, 0, imagedata.Lengt h)
Try
bmp = Bitmap.FromStre am(srm)
Dim g As Graphics = Graphics.FromIm age(bmp)
' Response.AddHea der("Content-Disposition", "attachment ")
Response.Conten tType = "image/JPEG"
bmp.Save(Respon se.OutputStream , ImageFormat.Jpe g)
'Response.End()
Catch ex As Exception
' Response.Write( ex.Message)
End Try
' Cleanup
'g.Dispose()
'bmp.Dispose()
End If
End If
%>[/code]Comment
Comment