Documente Academic
Documente Profesional
Documente Cultură
Articles
inShare3
7122
Examples
Suppose you are working on a project in a team of 1000 members. There are many
members shifted day by day due to some problems. When any new member is
assigned for this project, then he can easily understand the concept of 3-Tier
Architecture and be involved in the project. If the companies are working on a 1-Tier
Architecture then the shifting of an employee from one project to another project is
not possible.
In 3-Tier, you can easily update any tier of code. But in 1-Tier, it is not possible.
Each layer always uses your separate code, so it is easy to modify the code.
You can easily change any layer of code without affecting the other two layers.
Many people encounter problems because they lack good knowledge of OOP
concepts and other C# programming such as class, object, property and so on.
There are some steps to implement the 3-Tier Architecture concepts in ASP.NET applications.
In this application, I will explain how to build a 3-Tier registration and login page in
ASP.NET as given below:
In the following, I rovided code for all the classes and web forms.
Step 1
1. create database skyworld
2.
3. use skyworld
4.
Step 2
RegisterData.aspx Code
1. <table style="height: 304px; width: 393px">
2. <tr>
3. <td>First Name</td>
4. <td>:</td>
5. <td><asp:TextBox ID="txtfirst" runat="server" ></asp:TextBox></td>
6. </tr>
7.
8. <tr>
9. <td>Last Name</td>
10. <td>:</td>
11. <td><asp:TextBox ID="txtlast" runat="server" ></asp:TextBox></td>
12. </tr>
13. <tr>
14. <td>User Name</td>
15. <td>:</td>
16. <td><asp:TextBox ID="txtuser" runat="server" ></asp:TextBox></td>
17. </tr>
18. <tr>
19. <td>Password</td>
20. <td>:</td>
21. <td><asp:TextBox ID="txtpassword" runat="server" ></asp:TextBox></td>
22. </tr>
23. <tr>
24. <td>Address</td>
25. <td>:</td>
26. <td><asp:TextBox ID="txtaddress" runat="server" ></asp:TextBox></td>
27. </tr>
28. <tr>
29. <td>Phone No</td>
30. <td>:</td>
31. <td><asp:TextBox ID="txtphoneno" runat="server" ></asp:TextBox></td>
32. </tr>
33. <tr>
34. <td></td><td></td>
<asp:Button ID="btnreset"
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
txtfirst.Text = "";
25.
txtlast.Text = "";
26.
txtuser.Text = "";
27.
txtpassword.Text = "";
28.
txtaddress.Text = "";
29.
txtphoneno.Text = "";
30.
31.
32.
33.
34.
studentdata.FirstName = txtfirst.Text;
35.
studentdata.LastName = txtlast.Text;
36.
studentdata.UserName = txtuser.Text;
37.
studentdata.password = txtpassword.Text;
38.
studentdata.Address = txtaddress.Text;
39.
studentdata.PhoneNumber = txtphoneno.Text;
40.
41.
try
42.
43.
44.
if (result != null)
45.
46.
47.
48.
else
49.
50.
51.
52.
53.
54.
55.
56.
//{
57.
// throw info;
58.
//}
59.
finally
60.
61.
studentdata = null;
62.
63.
64.
}
}
65. }
Step 3
Modify the BL layer BuninessLayer.cs as below:
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using dataLayer;
6.
7. namespace BuninessLayer
8. {
9.
10.
11.
12.
13.
14.
15.
16.
try
17.
18.
return datanew.registration_details(abc);
19.
20.
catch (Exception e)
21.
22.
throw e;
23.
24.
finally
25.
26.
datanew = null;
27.
28.
29.
30.
31. }
Step 4
Modify the DL Layer DataLayer.cs code as below:
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Data;
6. using System.Data.SqlClient;
7. using System.Configuration;
8.
9. namespace dataLayer
10. {
11.
12.
13.
14.
15.
16.
17.
SqlConnection sqlcon;
18.
SqlCommand sqlcmd;
19.
SqlDataAdapter sqldap;
20.
DataSet ds;
21.
22.
23.
24.
25.
26.
sqlcmd.Connection=sqlcon;
27.
sqlcmd.CommandType=CommandType.StoredProcedure;
28.
sqlcmd.CommandText="userdata";
29.
sqlcon.Open();
30.
31.
try
32.
33.
sqlcmd.Parameters.AddWithValue("@spfirstname",user_details.FirstN
ame);
34.
sqlcmd.Parameters.AddWithValue("@splastname",user_details.LastNa
me);
35.
sqlcmd.Parameters.AddWithValue("@spusername",user_details.UserN
ame);
36.
sqlcmd.Parameters.AddWithValue("@sppassword",user_details.passw
ord);
37.
sqlcmd.Parameters.AddWithValue("@sphouse",user_details.Address);
38.
sqlcmd.Parameters.AddWithValue("@spphone",user_details.PhoneNu
mber);
39.
40.
return sqlcmd.ExecuteNonQuery().ToString();
}
41.
42.
43.
44.
throw showerror;
45.
46.
finally
47.
48.
sqlcmd.Dispose();
49.
sqlcon.Dispose();
50.
51.
52.
53.
}
}
54. }
Write the C# property codes to get and set the data as given below:
1. public class studentlist
2. {
3.
4.
5.
6.
7.
8.
9.
10. }
Output
Or:
1. using System;
2. using System.Linq;
3. using System.Web;
4.
5.
/// <summary>
6.
7.
/// </summary>
8.
9.
10.
11.
12.
13.
14.
15.
16.
//use propertis concepts in C#,to get and set the value in variables
17.
18.
19.
20.
get
21.
22.
return user_name;
23.
24.
set
25.
26.
user_name = value;
27.
28.
}
}
29.
30.
31.
32.
get
33.
34.
return password;
35.
36.
set
37.
38.
password = value;
39.
40.
}
}
41.
42.
43.
44.
get
45.
46.
return qualification;
47.
48.
set
49.
50.
qualification = value;
51.
52.
}
}
53.
54.
55.
56.
get
57.
58.
return age;
59.
60.
set
61.
62.
age= value;
63.
64.
}
}
65.
66.
67.
68.
get
69.
70.
return mobile;
71.
72.
set
73.
74.
mobile = value;
75.
76.
77. }
}
}