0

テーブルにレコードを挿入するとき、「状態」列に「A」を挿入しています。
チェックボックスをオンにして削除ボタンをクリックした後、「A」を「N」に自動的に変更したいと思います。

手伝ってくれませんか?

string constr = ConfigurationManager.ConnectionStrings["webConnectionString"].ConnectionString;

protected void btnDelete_Click(object sender, EventArgs e)
{
   foreach (GridViewRow row in GridView1.Rows) {

        CheckBox chk = (CheckBox)row.FindControl("chkSelect");
        if (chk.Checked == true)
        {
            int cnt= int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
            SqlConnection con = new SqlConnection(constr);
            string sql = "delete from PA_webwork where sno = @sno ";
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.Parameters.AddWithValue("@sno", cnt);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
   GridView1.DataBind();
}

   database     :: web
   table name   :: PA_webwork

   column names ::

            sno         :: int
            article no  :: varchar(50)
            state       :: varchar(50)
            date        :: smalldatetime
4

1 に答える 1

1

あなたは更新ステートメントを書くことができます

            int cnt= int.Parse(GridView1.DataKeys[row.RowIndex].Value.ToString());
            SqlConnection con = new SqlConnection(constr);
            string sql = "update  PA_webwork set state 'N'  where sno = @sno ";
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.Parameters.AddWithValue("@sno", cnt);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
于 2013-08-26T09:12:00.920 に答える