C# .NET - how to add 3 tier implementation DAL AND BAL

Asked By kavitha varma on 13-Jun-12 01:20 AM
S K replied to kavitha varma on 13-Jun-12 01:41 AM
There are lots of confusion about 3 tier and layer some person using separate project within a solution one for DAL, 2nd for BAL, 3rd for presentation layer this is know as 3 layer not 3 tier, actually 3- tier means that project should completely separated in to 3 different layer and communicate among them by using web services so in real scenario we can host all three project on different machine.
dipa ahuja replied to kavitha varma on 13-Jun-12 02:55 AM
Presentation Layer (UI)
Presentation layer cotains pages like .aspx or windows form where data is presented to the user or input is taken from the user.

Business Access Layer (BAL) or Business Logic Layer
BAL contains business logic, validations or calculations related with the data, if needed. I will call it Business Access Layer in my demo.

Data Access Layer (DAL)
DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo application, I have taken a very simple example. I am assuming that I have to play with record of persons (FirstName, LastName, Age) and I will refer only these data throughout this article.
For this you have to add the  BAL , DAL code in the App_code folder
DAL :
public class DAL
{
  string connStr = ConfigurationManager.ConnectionStrings["connstring"].ToString();
 
    public DAL()
    {
      //
      // TODO: Add constructor logic here
      //
    }
  public static DataTable getdata(int empid)
  {
    SqlDataAdapter da = new SqlDataAdapter("select * from table1 where empid=" + empid, connStr);
    DataTable dt = new DataTable();
    da.Fill(dt);
    return dt;
  }
}
 
BAL
public class BAL
{
    public BAL()
    {
      //
      // TODO: Add constructor logic here
      //
    }
  public static DataTable getdata(int empid)
  {     
    try
    {
      return DAL.getdata(empid);
    }
    finally
    {
    }
  }
}
 
Use in PL
GridView1.DataSource = BAL.getdata(1);
 
kavitha varma replied to dipa ahuja on 13-Jun-12 07:12 AM
IN my DAL class why configuration manager was showing error it was not showing inthe intellesense.
dipa ahuja replied to kavitha varma on 13-Jun-12 07:34 AM
add these name spaces

using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI.HtmlControls;
kavitha varma replied to dipa ahuja on 13-Jun-12 07:49 AM
I added configuration name space here it was creating error


sing System;


using System.Data;


using System.Configuration;


using System.Web;


using System.Data.SqlClient;




using System.Data.SqlClient;


namespace DAL
{
    
    public class personDAL
    {
        string cs=configura
       
    }
}

dipa ahuja replied to kavitha varma on 13-Jun-12 07:50 AM
post the error coz after adding namespace error should not come