1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;//
12
13 public partial class Basic_Delete : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17 // 넘겨져 온 값이 없지 않다면,,,
18 if (!String.IsNullOrEmpty(Request["Num"])) {
19 this.lblNum.Text = Request["Num"];
20 }
21 else {
22 Response.Write("잘못된 요청입니다."); Response.End();
23 }
24 }
25 protected void btnDelete_Click(object sender, EventArgs e)
26 {
27 //[1] 변수 선언부
28 string strSql = "DeleteBasic";
29 #region 커넥션과 커멘드
30 //[2] 커넥션
31 SqlConnection objCon = new SqlConnection();
32 objCon.ConnectionString =
33 ConfigurationManager.ConnectionStrings[
34 "ConnectionString"].ConnectionString;//DB연결문자열지정
35 objCon.Open();
36 //[3] 커멘드
37 SqlCommand objCmd = new SqlCommand();
38 objCmd.Connection = objCon;
39 objCmd.CommandText = strSql;//
40 objCmd.CommandType = CommandType.StoredProcedure;//
41 #endregion
42 //[4] 파라미터 추가
43 objCmd.Parameters.AddWithValue("@Num", Request["Num"]);
44 objCmd.Parameters.AddWithValue("@Password", txtPassword.Text);
45 //[5] 실행
46 int result = objCmd.ExecuteNonQuery();
47 if (result > 0) // 해당 데이터가 삭제되면 1을 반환
48 {
49 Response.Redirect("List.aspx");//삭제 후 이동
50 }
51 else
52 {
53 lblError.Text = "암호가 틀립니다.";
54 }
55 //[6] 마무리
56 objCon.Close();
57 }
58 protected void btnCancel_Click(object sender, EventArgs e)
59 {
60 Response.Redirect("View.aspx?Num=" + Request["Num"]);//뒤로
61 }
62 }
63