-->
Implementation of three tier architecture:
-->
I have created one project as shown above name as 3-tier.
For implementation of three tier architecturewe need to separate all three
layers, so I have created business layer
(AddBAL.cs) , Data access layer (AddDAL.cs) and presentation layer (Default.aspx)
separately. We need to just reference BAL in presentation layer.
-->
Data Access Layer (DAL) :
AddDAL.cs
using
System;
using System.Data;
using System.Configuration;
public class AddDAL
{
string conStr = ConfigurationManager.ConnectionStrings
["ConnectionStringName"].ToString();
// Add records into database
public int AddMethod(string fName, string lName)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand Cmd = new SqlCommand("AddData", conn);
Cmd.CommandType = CommandType.StoredProcedure;
try
{
Cmd.Parameters.AddWithValue("@fName", fName);
Cmd.Parameters.AddWithValue("@lName", lName);
return Cmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
Cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
-->
Business Access Layer (BAL):
AddBAL.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
// Summary description for PersonBAL3
public class AddBAL
{
// Add records into database
public int AddMethod(string fName, string lName)
{
AddDAL ObjAdd = new AddDAL ();
try
{
return ObjAdd. AddMethod (fName, lName);
}
catch
{
throw;
}
finally
{
ObjAdd = null;
-->
Presentation Layer :
Default.aspx
Default.aspx.cs
protected void AddRecords(object sender, EventArgs e)
{
int intTotal = 0;
//insert records
AddBAL ObjBAL = new AddBAL ();
string firstName = txtFName.Text;
string lastName = txtLName.Text;
try
{
intTotal = ObjBAL.AddMethod(fName, lName)
}
catch (Exception Ex)
{
lblMessage.Text = Ex.Message.ToString();
}
finally
{
ObjBAL = null;
}
}
-->