کد:
protected void btnInsert_Click(object sender, EventArgs e) {
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=testDB;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_customer", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Id", txtID.Text);
cmd.ExecuteNonQuery();
con.Close();
Label4.Text = "اطلاعات با موفقیت ثبت شد";
GridView1.DataBind();
}
protected void btnEdit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=testDB;Integrated Security=True");
con.Open();
string sql = "update tbl_customer set cname=@cname , cfamily=@cfamily , caddress=@caddress where Id=@Id";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("cname", txtName.Text);
cmd.Parameters.AddWithValue("cfamily", txtFamily.Text);
cmd.Parameters.AddWithValue("caddress", txtAddress.Text);
cmd.Parameters.AddWithValue("Id", txtID.Text);
cmd.ExecuteNonQuery();
con.Close();
Label4.Text = "اطلاعات ویرایش شد";
GridView1.DataBind();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=testDB;Integrated Security=True");
con.Open();
string sql = "delete from tbl_customer where Id=@Id";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("Id", txtID.Text);
cmd.ExecuteNonQuery();
con.Close();
Label4.Text = "رکورد مورد نظر حذف شد";
GridView1.DataBind();
}