ASP.Net Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Puneet Gupta
    New Member
    • Apr 2008
    • 2

    ASP.Net Problem

    how to Retrive Image in Data Base(Sql Server2000)
  • Stang02GT
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Originally posted by Puneet Gupta
    how to Retrive Image in Data Base(Sql Server2000)
    This article will answer your question

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      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]
      Last edited by Frinavale; Apr 16 '08, 01:33 PM. Reason: added [code] tags

      Comment

      Working...