DOT NET
DOT NET
NET WEB FROM USING HTML SERVER CONTROLS TO ENTER JOB SEEKERS DETAIL
INPUT:
<html>
<body>
@{
if (IsPost)
{
string companyname = Request["CompanyName"];
string contactname = Request["ContactName"];
<p>You entered: <br>
Company Name: @companyname <br>
Contact Name: @contactname </p>
}
else
{
<form method="post" action="">
Company Name:<br>
<input type="text" name="CompanyName" value=""><br>
Contact Name:<br><br>
<input type="text" name="ContactName" value=""><br><br>
<input type="submit" value="Submit" class="submit">
</form>
}
}
</body>
</html>
OUTPUT:
2) Write An Asp.Net Application To Retrive Form Date And Display It Hte Client Browser In A Table
Format
INPUT:
OUTPUT:
3) Create an application using Date grid control to access information’s from table in SQL Server.
INPUT:
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Windows;
namespace DataGridSQLExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
AdventureWorksLT2008Entities dataEntities = new AdventureWorksLT2008Entities();
public MainWindow()
{
InitializeComponent();
}
dataGrid1.ItemsSource = query.ToList();
}
}
}
OUTPUT:
4) Create an application using Data grid control to access information’s from table in SQL server.
INPUT:
private void btnRefresh_Click(object sender, EventArgs e)
{
//set the connection string
string connString = @"Server =.\SQL2K17; Database = SampleDB; Trusted_Connection =
True;"try
{
//sql connection object
using (SqlConnection conn = new SqlConnection(connString))
{
//retrieve the SQL Server instance version
string query = @"SELECT e.id,
e.code,
e.firstName,
e.lastName,
l.code AS locationCode,
l.descr AS locationDescr
FROM dbo.employees e
INNER JOIN dbo.location l
ON l.id = e.locationID;"//define the SqlCommand object
SqlCommand cmd = new SqlCommand(query, conn);
//close connection
conn.Close();
}
}
catch (Exception ex)
{
//display error message
MessageBox.Show("Exception: " + ex.Message);
}
}
OUTPUT:
5) Create an application using Data list control to access information’s from table in SQL Server and display the
result in neat format.
INPUT:
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. using System.Configuration;
8. using System.Data;
9. using System.Data.SqlClient;
10.
11. public partial class UI_DataList : System.Web.UI.Page
12. {
13. string connection = ConfigurationManager.ConnectionStrings["connstring"].C
onnectionString;
14. protected void Page_Load(object sender, EventArgs e)
15. {
16. if (!IsPostBack)
17. {
18. GetEmpDataList();
19. }
20. }
21. protected void btnSave_Click(object sender, EventArgs e)
22. {
23. using (SqlConnection con = new SqlConnection(connection))
24. {
25. using (SqlCommand cmd = new SqlCommand("sp_InsertEmployeeData",
con))
26. {
27. cmd.CommandType = CommandType.StoredProcedure;
28.
29. cmd.Parameters.AddWithValue("@EmpName", SqlDbType.VarChar).V
alue = txtName.Text.Trim();
30. cmd.Parameters.AddWithValue("@Contact", SqlDbType.NChar).Value
= txtContact.Text.Trim();
31. cmd.Parameters.AddWithValue("@EmailId", SqlDbType.NVarChar).Val
ue = txtEmail.Text.Trim();
32.
33. con.Open();
34. cmd.ExecuteNonQuery();
35. con.Close();
36.
37. Clear();
38. Response.Write("<script type=\"text/javascript\">alert('Record Insert
ed Successfully');</script>");
39. GetEmpDataList();
40. }
41. }
42. }
43. void Clear()
44. {
45. txtName.Text = String.Empty;
46. txtContact.Text = String.Empty;
47. txtEmail.Text = String.Empty;
48. }
49. private void GetEmpDataList()
50. {
51. using (SqlConnection con = new SqlConnection(connection))
52. {
53. SqlDataAdapter sd = new SqlDataAdapter("sp_FillData", con);
54. sd.SelectCommand.CommandType = CommandType.StoredProcedure;
55. DataTable dt = new DataTable();
56.
57. sd.Fill(dt);
58.
59. if (dt.Rows.Count > 0)
60. {
61. DataListEmp.DataSource = dt;
62. DataListEmp.DataBind();
63. }
64. }
65. }
66. protected void DataListEmp_DeleteCommand(object source, DataListComman
dEventArgs e)
67. {
68. int EmpID = Convert.ToInt32(DataListEmp.DataKeys[e.Item.ItemIndex].ToSt
ring());
69.
70. using (SqlConnection con = new SqlConnection(connection))
71. {
72. using (SqlCommand cmd = new SqlCommand("sp_DeleteEmployeeData",
con))
73. {
74. cmd.CommandType = CommandType.StoredProcedure;
75. cmd.Parameters.AddWithValue("@EmpID",EmpID);
76.
77. con.Open();
78. cmd.ExecuteNonQuery();
79. con.Close();
80.
81. Response.Write("<script type=\"text/javascript\">alert('Record Delete
d Successfully');</script>");
82. GetEmpDataList();
83. }
84. }
85. }
86. protected void DataListEmp_EditCommand(object source, DataListCommandE
ventArgs e)
87. {
88. DataListEmp.EditItemIndex = e.Item.ItemIndex;
89. GetEmpDataList();
90. }
91. protected void DataListEmp_CancelCommand(object source, DataListComma
ndEventArgs e)
92. {
93. DataListEmp.EditItemIndex = -1;
94. GetEmpDataList();
95. }
96. protected void DataListEmp_UpdateCommand(object source, DataListComma
ndEventArgs e)
97. {
98. int EmpID = Convert.ToInt32(DataListEmp.DataKeys[e.Item.ItemIndex].ToS
tring());
99.
100. TextBox txtName = (TextBox)e.Item.FindControl("txtName");
101. TextBox txtContact = (TextBox)e.Item.FindControl("txtContact");
102. TextBox txtEmail = (TextBox)e.Item.FindControl("txtEmail");
103.
104. using (SqlConnection con = new SqlConnection(connection))
105. {
106. using (SqlCommand cmd = new SqlCommand("sp_UpdateEmployeeData
", con))
107. {
108. cmd.CommandType = CommandType.StoredProcedure;
109.
110. cmd.Parameters.AddWithValue("@EmpID", EmpID);
111. cmd.Parameters.AddWithValue("@EmpName", SqlDbType.VarChar).V
alue = txtName.Text.Trim();
112. cmd.Parameters.AddWithValue("@Contact", SqlDbType.NChar).Value
= txtContact.Text.Trim();
113. cmd.Parameters.AddWithValue("@EmailId", SqlDbType.NVarChar).Val
ue = txtEmail.Text.Trim();
114.
115. con.Open();
116. cmd.ExecuteNonQuery();
117. con.Close();
118.
119. Clear();
120. Response.Write("<script type=\"text/javascript\">alert('Record Updat
e Successfully');</script>");
121. DataListEmp.EditItemIndex = -1;
122. GetEmpDataList();
123. }
124. }
125. }
126. }
OUTPUT: