3 Tier Architecture in Asp Net Using C Example Pdf
In this asp.net tutorial you will learn how to implement 3-tier architecture in asp.net using c#. 3-Tier architecture is also called layered architecture. Some people called it n-tier architecture. Layer architectures are essentially objects and work in object oriented environment just like asp.net. 3-tier architecture is a very well known architecture in the world of software development, it doesn't matter whether you are developing web based application or desktop based, it is the best architecture to use.
3-Tier architecture consists of
1) UI or Presentation Layer
2) Business Access Layer or Business Logic Layer
3) Data Access Layer
Presentation Layer
Presentation layer consists of pages like .aspx or desktop based form where data is presented to users or getting input from users.
Business Logic layer or Business Access Layer
Business logic layer contains all of the business logic. Its responsibility is to validate the business rules of the component and communicating with the Data Access Layer. Business Logic Layer is the class in which we write functions that get data from Presentation Layer and send that data to database through Data Access Layer.
Data Access Layer
Data Access Layer is also the class that contains methods to enable business logic layer to connect the data and perform desired actions. These desired actions can be selecting, inserting, updating and deleting the data. DAL accepts the data from BAL and sends it to the database or DAL gets the data from the database and sends it to the business layer. In short, its responsibility is to communicate with the backend structure.
Illustration of 3-Tier Architecture with Diagram
The figure clearly describe about the purpose of BAL and DAL. The main advantage of 3-tier architecture is to separate the presentation layer from data access layer. You will not write any function to communicate with database in presentation layer, all the required functions for communication with database will be available in DataAcessLayer. Its mean at presentation layer you will just focus at information that you will present in front of user.
Example Below:
Table Script
CREATE TABLE [dbo].[EmpData](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) NULL,
[gender] [nvarchar](50) NULL,
[address] [nvarchar](50) NULL,
[email] [nvarchar](50) NULL,
[country] [nvarchar](50) NULL,
[phone] [int] NULL,
[image] [nvarchar](50) NULL,
CONSTRAINT [PK_EmpData] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE PROCEDURE [dbo].[showFullData]
@id int
AS
BEGIN
select * from EmpData where id=@id
END
CREATE PROCEDURE [dbo].[DeleteUser]
@id int
AS
BEGIN
delete from EmpData where id=@id
END
CREATE PROCEDURE [dbo].[employeedata]
@name nvarchar(50),
@gender nvarchar(50),
@address nvarchar(50),
@email nvarchar(50),
@country nvarchar(50),
@phone int,
@image nvarchar(50)
AS
BEGIN
insert into EmpData values(@name,@gender,@address,@email,@country,@phone,@image)
END
CREATE PROCEDURE [dbo].[updateEmpData]
@id int,
@name nvarchar(50),
@gender nvarchar(50),
@address nvarchar(50),
@email nvarchar(50),
@country nvarchar(50),
@phone int,
@image nvarchar(50)
AS
BEGIN
update EmpData set name=@name,gender=@gender,address=@address,email=@email,country=@country,phone=@phone,image=@image
where id=@id
END
CREATE PROCEDURE [dbo].[showDetail]
AS
BEGIN
select * from EmpData
END
Now Come To Bussiness Layer
BAL:
Classes in Bussiness Layer:
Now Come To Data Access Layer
DAL:
using System.Configuration;
using BussinessLayer;
namespace DataLink
{
public class DAL
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["precticedata"].ConnectionString);
#region Adduserdetail
public int insertdetail(UserInfo1 obdef)
{
int res = 0;
try
{
con.Open();
SqlCommand cmd = new SqlCommand("employeedata", con);
cmd.Parameters.Add("@name", obdef.name);
cmd.Parameters.Add("@gender", obdef.gender);
cmd.Parameters.Add("@address", obdef.address);
cmd.Parameters.Add("@email", obdef.email);
cmd.Parameters.Add("@country", obdef.country);
cmd.Parameters.Add("@phone", obdef.phone);
cmd.Parameters.Add("@image", obdef.image);
cmd.CommandType = CommandType.StoredProcedure;
res = cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
throw ex;
}
return res;
}
0 Response to "3 Tier Architecture in Asp Net Using C Example Pdf"
Post a Comment