0

hi everyone. I want to retrieve image from sql server database using asp.net with vb, but the image is not display and I don't know what is wrong with my code. please help me.

Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing
Public Class _Default
    Inherits System.Web.UI.Page
    Public sqlcon As SqlConnection = New SqlConnection("server=.; database=batool; Trusted_Connection=yes;")
    Public sqlcmd As SqlCommand
   Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Try
            Dim picname As String
            sqlcon.Open()
            sqlcmd = New SqlCommand("select photo from qq", sqlcon)
            Dim reader As SqlDataReader = sqlcmd.ExecuteReader
            If reader.Read Then
                picname = reader("photo")
                Image1.ImageUrl = Server.MapPath(picname)
            End If
            sqlcon.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
3
Contributors
5
Replies
32
Views
2 Years
Discussion Span
Last Post by G_Waddell
0

thank you for reply me. I have save the location image in the database not the image themselve and the path is correct, I don't know how to display the image to the image control.

0

I understand that you ahve saved the path and not the image. You have done it correctly... Image1.ImageUrl = " ... ".

run the page and look at teh page source to see what was actually loaded in for the <img src /> attribute.

0

Hi,
You've posted a similar issue on another post...(I answered that one for you) but in that one you were opening the file directly in the browser, this post you are wanting to open the image inside a page? Could you post your ASP.Net page code?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.