Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when am creating any application just am writing all the code in a single file

For example:
Am creating login page in asp.net with Sql Server2008

how to implement in 3tire

give me Simple Understanding
Posted

First Create BEL.CS (Business Entity Layer)

BEL.CS

C#
private string _UserName;
private string _Password;

public string UserName
{
get
{return _UserName;
}
set
{
_UserName = value;
}
}

public string Password
{
get
{
return _Password;
}
set
{
_Password = value;
}
}



Second One For DAL.CS (Data Access Layer)

C#
//SQL Connection string 
string ConnectionString = ConfigurationManager.AppSettings["LocalConnection"].ToString();


public string UserInformation(BEL objBELUserDetails)
{
SqlConnection con = new SqlConnection(ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@UserName",objBELUserDetails.UserName);
cmd.Parameters.AddWithValue("@Password", objBELUserDetails.Password);
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
string strMessage = (string) cmd.Parameters["@ERROR"].Value;
con.Close();
return strMessage;
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Dispose();
con.Close();
con.Dispose();
}
}



Third One For BLL.CSS (Business Access Layer)

BLL.CSS
C#
public string UserDetails(BEL objUserDetails)
{
DAL objUserDAL = new DAL();
try
{
return objUserDAL.UserInformation(objUserDetails);
}
catch (Exception ex)
{
throw ex;
}
finally
{
objUserDAL = null;
}
}


Now In Presentation Layer

My Login.aspx.cs

C#
protected void btnlogin_Click(object sender, EventArgs e)
{
try
{
string Output = string.Empty;
BEL objUserBEL = new BEL();

objUserBEL.UserName = txtuser.Text;
objUserBEL.Password = txtpwd.Text;
BLL objUserBLL = new BLL();
Output = objUserBLL.InsertUserDetails(objUserBEL);
Response.Redirect("Home.aspx");
}
catch(exception ex)
{

}
} 
 
Share this answer
 
v2
Here is the tutorial on how to create a 3-tier architecture: Creating ASP.NET Applications with N-Tier Architecture[^]

and here is one example site for the same: YaBlogEngine - A Tiny Blog Engine written in ASP.NET/C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900