Asp.Net Image Upload in 3-Tier Architecture and store in sql database

Introduction : 

In  3-Tier Architecture for displaying image we have using here, gridview control and sql database connection, now you can follow the below step and display image using 3- tier architecture in c#.  Asp.Net Image Upload using 3 Tier Architecture with sql server database, file upload using n tier architecture

step 1 : Open Visual Studio and Create new web project

Step 2 : Create Database 3-Tier Architecture


Step 3 : Now create class data

public class DAL

int id { get; set; }
public string photo { get; set; }}

Step 4 : Create Class BAL.cs This class called as Business layer.

public class BAL
SqlConnection con = new SqlConnection(@”Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True“);
public void insert_data(DAL da)
SqlCommand cmd = new SqlCommand(“insert into user_master values(‘” + + “‘)”, con);
public DataTable Select_data(DAL da)
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(“select * from user_master“, con);
return dt;

Step 5 : Now, add webform and give name web.aspx and add Gridview, in Gridview source code we can add following source

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False”>
<asp:TemplateField HeaderText=”photo”>
<asp:image ID=”Image1″ runat=”server” Height=”70px” Width=”70px”
ImageUrl ='<%#Eval(“photo”)%>’></asp:image>

<asp:image ID=”Image2″ runat=”server”  Height=”70″
Width=”70″ ImageUrl ='<%#Eval(“photo”)%>’></asp:image>




Step 6:

Now you can add code Behind following here file_id is used as browse id using this id can select image from the folder. and we can add folder named as photo we can retrieve image from this folder by below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
namespace _3_tier_Image
public partial class Web : System.Web.UI.Page
DAL da = new DAL();
BAL ba = new BAL();

protected void Page_Load(object sender, EventArgs e)

public void Grid()
DataTable dt = new DataTable();
dt = ba.Select_data(da);
GridView1.DataSource = dt;


protected void Button1_Click(object sender, EventArgs e)

if (file_id.HasFile)

string file = Path.GetFileName(file_id.FileName);
file_id.SaveAs(MapPath(“~/photo/”) + file); = “~/photo/” + file;
Response.Write(“Image Inserted………..“);

Step 7: Run Project and Select Image from Folder

Asp.Net Image Upload in 3-Tier Architecture and store in sql database




Leave a Reply

Your email address will not be published.