3 – Tier Architecture Example in ASP.Net C#

In this asp.net tutorial post we will learn how to create 3 tier architecture application using asp.net with c#.
Basically three tier architecture means our project divided into three main layers or we can also say our project developed and maintained in to three separate layers.

1.  Presentation Layer (UI – User Interface Layer)

2. Business Logic Layer (use for write logic code)

3. Data Access Layer (DAL user for connectivity with Database)

Many developer have confusion about how to create project in three tier architecture and what is three tier architecture.

today, i will expalin in detail about structure of three tire and how to develop application in 3 tier architecture with an example, In three tier architecture in .net there are separate code of user interface, business logic and data access layer.

After reading this asp.net post all doubt will be cleared of 3 tier architecture.

Here, we will understand all the three layers with take a simple asp.net example with c#.

First lets understand main three layers of three tier architecture:

1. Presentation Layers or User Interface Layer
- Presentation layer is a user interface layer where we can design our web page or windows page. It is basically our aspx page or Html page where we can make design with controls. UI is a intermedialte between user and business logic layer. In other simple word we can say Presentation layes where user can give input and get some result as output.

2. Business logic layer (BLL)
- Business layer is intermidiate or middle layer that communicate presentation layer and Data access layer.
Business layer used to validate input condition and corerect the date before calling method from the data layer.
In Business layer we can write our businness logic code and validation code as per the project requirements.

3. Data Access Layer (DAL)
- Data Access Layer used to make connection with database server. In data access layer we can write database query, stored procedure for insert, update, delete, select opration on database.This layer only communicate with Business logic layer.

Now, Let’s start to creating a three tier architecture application in asp.net
we will understand all the procees by some steps by step to make it easy and clearly.

STEP 1 : Create ASP.Net web application

First open the visual studio and create a new asp.net web application.
open visual studio –> File menu –>New –>Website

Select ASP.Net web site and declare name “ThreeExample” as website name.

Create ASP.Net three tier architecture web application.

Create ASP.Net three tier architecture web application.

Here, we have created asp.net web application.

STEP 2 : Design the default.aspx page for user Registration.

Now, design the default.aspx page as shows like below for simple user registration form.

Above is the html code for design web forms.

Create ASP.Net three tier architecture web application.

Create ASP.Net three tier architecture web application.

above is the output of simple user registration web forms.

STEP 3 : Create New Database in SQL – Server

Now, create new database in sql server named “ThreeExp”, and create a new table “UserMst” in newly created sql database.

Here, we see the columns in UserMst table.

Create new table in database for 3 tier web application.

Create new table in database for 3 tier web application.

After creating new table create new stored procedure for insert records and select records.

Stored Procedure for SELECT

stored Procedure for INSERT

STEP 4 :  Create new class Library for Data Access Layer.

right click on solution — >> ADD — >> New Project –>> Class Library

Add New Class Library for 3 tier asp.net web application.

Add New Class Library for 3 tier asp.net web application.

select Class Library option as show below figure and named “DataLayer” for new class library project.

Add New Class Library for 3 tier asp.net web application.

Add New Class Library for 3 tier asp.net web application.

Now, we all know as write sql connection code in data access layer. There are many methods developer uses for sql connectivity. we here explain two methods for sql connectivity. first using DataSet and second using Data Adapter.

STEP 5 : Connection with DataSet using Different connection method

let’s try with first method using DataSet.

Create new DataSet in Data Layer Class Library project and bind select and insert stored procedure in DataSet.

DataLayer –> Add –> New Item –> DataSet

ADD New DataSet in Data Layer for sql database connectivity

ADD New DataSet in Data Layer for sql database connectivity

set the new dataset name as “DS_User”.

ADD New DataSet in Data Layer for sql database connectivity

ADD New DataSet in Data Layer for sql database connectivity

after creating new dataset follow some step to make sql connectivity like below.

Create new Table Adapter in DataSet and bind select and inset stored procedure.

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

 

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

Make connection between asp.net and sql using DataSet

after taking this steps we are successfully connected with sql server database and same time the connection string will be generate in web.config file.

STEP 6 : write code in Data Access Layer

write below code in Data access layer :

Here we use DataSet method for connectivity.

In above code in Data Access layer we use DataSet method for connectivity.

here is second method uses SQL DataAdapter method for connectivity like below.
before write code in data access layer we must import one references in data access layer for use method of ConfigurationManager.

DataLayer — > References — > Add References –> .NET –> System.Configuration

Add References to Data Access Layer for connection string.

Add References to Data Access Layer for connection string.

Add References to Data Access Layer for connection string.

Add References to Data Access Layer for connection string.

Add References to Data Access Layer for connection string.

Add References to Data Access Layer for connection string.

 

Now write below code for sql connection in data access layer using Data Adapter and SQL connection Method.

up to this we have done all the work in Data Access layer with two different methods.

Now, let’s create Business logic layer for use all data access method of user select and insert.

STEP 7 : Create Business Logic Layer (BLL)

Repeat same process as we created Data Access layer. Here creating new class library project named “BusineesLayer”.

Create New Class Library project  Business Logic Layer in asp.net

Create New Class Library project Business Logic Layer in asp.net

Now, we have see the three tier architecture in our application clearly.

Three tier architecture example in asp.net c#

Three tier architecture example in asp.net c#

Now, after creating business layer class library import namespace of database layer by adding references manually as show below:

BusinessLayer –> References –> Add References –> Project –> DataLayer

Add data access class references to business layer.

Add data access class references to business layer.

 

Add data access class references to business layer.

Add data access class references to business layer.

After importing references create data layer class object in business logic layer class.

write code in business layer for communicate data layer and presentation layer.

first import namespace
using DataLayer;

 

STEP 8 : Finally work on Presentation Layer

Now, in our three tier web application import add references of business layer into web application references folder.

web application –> Add References –> Project –> Business layer

Add references of business layer into web application references folder.

Add references of business layer into web application references folder.

Add references of business layer into web application references folder.

Add references of business layer into web application references folder.

Add references of business layer into web application references folder.

Add references of business layer into web application references folder.

Now, come back on asp.net web form to make insert and select user records.

The three tier architecture application example result is :

The ASP.Net 3 tier architecture application example in c#.

The ASP.Net 3 tier architecture application example in c#.

 

Hope this 3 – tier asp.net application post will help you……….

One Response to 3 – Tier Architecture Example in ASP.Net C#

  1. Kashyap says:

    its a really nice article ….

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 6 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">