블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

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

Category

Recent Post

Recent Comment

Archive

2009. 9. 28. 12:17 .Net Project/ADO.NET 3.5
반응형
 

Category Modify, Delete .Cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Configuration;

public partial class Category_FrmCategoryModify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //수정
    protected void btnModify_Click(object sender, EventArgs e)
    {
        string deleteQuery = @"Update Categories Set CategoryName = 
              @CategoryName Where CategoryID = @CategoryID";
                 SqlConnection con = new SqlConnection
                 (ConfigurationManager.ConnectionStrings
                 ["ConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand(deleteQuery, con);
                   cmd.CommandType = CommandType.Text;
      
        //파라미터 추가
        cmd.Parameters.AddWithValue
                                      ("@CategoryID", txtCategoryID.Text);
        cmd.Parameters.AddWithValue
                                      ("@CategoryName", txtCategoryName.Text);

        int recordAffected = cmd.ExecuteNonQuery();

        lblDisplay.Text = recordAffected.ToString() + "개가 변경됨";
        con.Close();


    }


    //삭제
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        //[1]변수선언부, 커넥션
        string deleteQuery =
                   "Delete Categories Where CategoryID = @CategoryID";

        SqlConnection con = new SqlConnection
                        (ConfigurationManager.ConnectionStrings
                        ["ConnectionString"].ConnectionString);
        con.Open();

        //[2]커맨드
        SqlCommand cmd = new SqlCommand(deleteQuery, con);
        cmd.CommandType = CommandType.Text;

        //[3]파라미터 추가
        cmd.Parameters.AddWithValue("@CategoryID", txtCategoryID.Text);

        //[4]실행
        int recordAffected = cmd.ExecuteNonQuery();

        //[5]마무리
        lblDisplay.Text = recordAffected.ToString() + "개가 변경됨";
        con.Close();
    }
}



반응형
posted by Magic_kit