使用ASP.NET完成对数据的增删改查操作,数据库使用MSSQL.
DATABASE TABLE: Sites
1 | ID INT IDENTITY(1,1) PRIMARY KEY, |
Question 1
Based on above MSSQL database table, using ASP.NET C# to insert one record into database.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39protected void rbtnAddSubmit_Click(object sender, EventArgs e)
{
if (ValidateInput("ADD"))
{
/* VARIABLE */
string name = rtxtAddName.Text.Trim();
string nfcCode = rtxtAddNfcCode.Text.Trim();
bool isArmorySite = Convert.ToBoolean(rcbbAddArmorySite.SelectedValue);
string armoryId = rtxtAddArmoryID.Text.Trim();
int companyId = user.CompanyUid;
string status = "Active";
SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;
/* INSERT YOUR CODE HERE */
RadGrid1.Rebind();
plhAddItem.Visible = false;
plhMain.Visible = true;
AlertMessage("Success! New site has been added!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }
connection.Dispose();
}
}
}
Question 2
Based on above MSSQL database table, using ASP.NET C# to update one record by given record ID and other information.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40protected void rbtnEditSubmit_Click(object sender, EventArgs e)
{
if (ValidateInput("EDIT"))
{
/* VARIABLE */
string id = hdfRecordId.Value.Trim();
string name = rtxtEditName.Text.Trim();
string nfcCode = rtxtEditNfcCode.Text.Trim();
bool isArmorySite = Convert.ToBoolean(rcbbEditArmorySite.SelectedValue);
string armoryId = rtxtEditArmoryID.Text.Trim();
int companyId = user.CompanyUid;
string status = "Active";
SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;
/* INSERT YOUR CODE HERE */
RadGrid1.Rebind();
plhEditItem.Visible = false;
plhMain.Visible = true;
AlertMessage("Success! Site has been updated!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }
connection.Dispose();
}
}
}
Question 3
Based on above MSSQL database table, using ASP.NET C# to delete one record by given record ID.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31protected void rbtnDeleteSubmit_Click(object sender, EventArgs e)
{
if (ValidateInput("Delete"))
{
/* VARIABLE */
string id = hdfRecordId.Value.Trim();
SqlConnection connection = Utility.GetConnection();
SqlCommand command = new SqlCommand();
try
{
connection.Open();
command.Connection = connection;
/* INSERT YOUR CODE HERE */
RadGrid1.Rebind();
AlertMessage("Success! Site has been removed!");
}
catch (Exception ex)
{
AlertMessage("Error! Please contact company helpdesk!");
}
finally
{
try { connection.Close(); }
catch { }
connection.Dispose();
}
}
}