Click here to Skip to main content
11,703,631 members (68,340 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 13-Feb-13 22:03pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First Create BEL.CS (Business Entity Layer)

BEL.CS

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)

//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
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

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)
{
 
}
} 
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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#[^]
  Permalink  

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

  Print Answers RSS
0 Maciej Los 570
1 OriginalGriff 500
2 Sergey Alexandrovich Kryukov 410
3 F-ES Sitecore 165
4 Andy Lanng 159
0 OriginalGriff 8,519
1 Sergey Alexandrovich Kryukov 7,667
2 CPallini 4,987
3 Maciej Los 4,686
4 Mika Wendelius 3,566


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100