Skip to main content

How add image from SQLServer database to Asp.Net

Display image from Database to page.
                            Today website  with image, video or text are dynamically change everyday. Most trainer don't how to add image from database. Most try to store image in database binary, there are some disadvantage in that slow response or wastage of memory etc.
Add Image from database

In design page try this tag.
 <asp:Image id="gvimg" runat="server" ImageUrl='<%#Eval("image_url")%>'  Width ="60px" Height ="40px" /> 

in Code behind page code. if want c# code convert this code using convert tool.

Imports System.Data
Imports System.Data.SqlClient

Dim ds As New DataSet
        Dim dadp As SqlDataAdapter
        Dim i, j As Integer
        str2 = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
        Dim con1 As SqlConnection = New SqlConnection(str2)
        dadp = New SqlDataAdapter("SELECT   *   FROM [job_info] where jobid=1", con1)
        dadp.Fill(ds, "temp1")
i = ds.Tables("temp1").Rows.Count
        For j = 0 To i - 1 Step j + 1
                  gvimg.ImageUrl = ds.Tables("temp1").Rows(j)("image_url").ToString()
Through image id gvimg we set image location. Next post we see how to upload image and how store imageurl. 


  1. How to connect to sql server database.


Post a Comment