Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi everyone. I have save the URL of the image in the database, and I want to retrieve these image in the image control. Can you help me please.
this is the code that I have used.
ASP.NET
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Image
Imports System.Data
Imports System.Web.UI.WebControls.Image
Imports System.Web
Imports System.Web.UI
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 = (picname)

            End If
            sqlcon.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class



and this is the URL that save in the database
C:\Users\duaa\Downloads\test1\image.orig\0.jpg
Posted
Updated 22-May-15 8:00am
v3
Comments
Sergey Alexandrovich Kryukov 22-May-15 8:55am    
Help with what? What's your problem?
—SA
duaa20 22-May-15 11:15am    
the problem is the image is not display
Sergey Alexandrovich Kryukov 22-May-15 12:23pm    
You are not showing where you try to show an image. How can I know where you screw up something?
—SA
duaa20 22-May-15 12:45pm    
this is my code
Imports System.Data.SqlClient
Imports System.IO
Imports System.Drawing.Image
Imports System.Data
Imports System.Web.UI.WebControls.Image
Imports System.Web
Imports System.Web.UI
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 = (picname)

End If
sqlcon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class


<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="Button1" runat="server" Height="50px" Text="Button"
Width="154px" />
<asp:Image ID="Image1" runat="server" imageurl="" Height ="100" Width="100" />
Sergey Alexandrovich Kryukov 22-May-15 12:49pm    
First, don't write code in comments; it is unreadable. Please move it to the question.
Anyway, you are not showing it all. Where Image1 is declared? (Never use auto-generated names!)
Did you check up the URL? Did you use the debugger? How about an example of your URL?
—SA

1 solution

Please look into the below links :

http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx

http://www.aspsnippets.com/Articles/Retrieve-images-using-a-file-path-stored-in-database-in-ASPNet.aspx[^]

http://stackoverflow.com/questions/19724742/display-image-in-aspimage-from-getting-path-from-sql-server[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900