How to retrieve image from db and show in image control in Asp.net 4.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sangituttu
    New Member
    • Jan 2013
    • 5

    How to retrieve image from db and show in image control in Asp.net 4.0

    This is my code
    Code:
    Public con1 As New SqlConnection("Data Source=ashii\sqlexpress;Initial Catalog=testing;Integrated Security=SSPI")
     con1.Open()
            Dim cmd As New SqlCommand("select max(pid) from photo ", con1)
            Dim k As New Integer
            k = cmd.ExecuteScalar
            Dim cmd1 As New SqlCommand("select photo from photo where pid='" & k & "'", con1)
            Dim p As String
            p = cmd1.ExecuteScalar().ToString
            Image1.ImageUrl = HttpContext.Current.Request.PhysicalApplicationPath + "picture\" + p.ToString
    plz help me to solve the error
    Last edited by Meetee; Jan 16 '13, 11:43 AM. Reason: Use code tags <code/> around code
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    What error are you getting?

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      So your image is stored in the database?

      You either need to store that image as a file on the server in a directory where the web browser can request the file....

      Or you need to create a control that retrieves the image from the database and writes it into the output stream to send to the browser based on the id.

      I posted such a solution for some one here.

      -Frinny

      Comment

      Working...