protected void Del_Click(string R_no) { SqlConnection Conn = new SqlConnection(); Conn.ConnectionString = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString; DataTable dt = new DataTable(); try { string CmdString = @""; CmdString = @"DELETE FROM DealersR where R_no=@R_no "; SqlCommand cmd = new SqlCommand(CmdString, Conn); cmd.Parameters.AddWithValue("R_no", R_no); Conn.Open(); cmd.ExecuteNonQuery(); DataTable dt2 = Dealers(); Grid_Dealers.DataSource = dt2; Grid_Dealers.DataBind(); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除成功')</script>", false); } catch (Exception ex) { DB_string.log("Dealers_del:", ex.ToString()); ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "<script>swal('刪除失敗','地區尚未全刪除')</script>", false); } finally { Conn.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["Username"] == null) { Response.Redirect("../../login.aspx"); } else { DataTable dt = Dealers(); Grid_Dealers.DataSource = dt; Grid_Dealers.DataBind(); } } }