public bool EditLOP(lop lp, string malop) { SqlConnection conn = new SqlConnection(connectString); string sql = @"UPDATE LOP SET TenLop= @tenlop, MaNganh= @manganh WHERE MaLop= @malop"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@malop", malop); cmd.Parameters.AddWithValue("@tenlop", lp.TenLop); cmd.Parameters.AddWithValue("@manganh", lp.MaNganh); conn.Open(); int dem = cmd.ExecuteNonQuery(); conn.Close(); return(dem >= 1); }
//string tenlop , string manganh public bool addLOP(lop lp) { SqlConnection conn = new SqlConnection(connectString); string sql = @"INSERT INTO LOP (TenLop, MaNganh) VALUES (@tenlop, @manganh)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@tenlop", lp.TenLop); cmd.Parameters.AddWithValue("@manganh", lp.MaNganh); conn.Open(); int dem = cmd.ExecuteNonQuery(); conn.Close(); return(dem >= 1); }
protected void Button2_Click(object sender, EventArgs e) { int ddlng = int.Parse(ddlnganh2.SelectedValue); //string mn = ddlnghanh.SelectedValue.ToString(); lop lp = new lop(txtlop.Text, ddlng); if (lopdao.EditLOP(lp, txtmalop.Text)) { Label1.Text = "DA EDIT"; grvlop.DataSource = lopdao.getTalbe("select * from LOP "); grvlop.DataBind(); } else { Label1.Text = "ERROR EDIT"; } }
protected void btnadd_Click(object sender, EventArgs e) { // int nganh = int.Parse(ddllop2.Text); // int mn = Convert.ToInt32(ddlnghanh.SelectedValue.ToString()); int ddlng = int.Parse(ddlnganh2.SelectedValue); //string mn = ddlnghanh.SelectedValue.ToString(); lop lp = new lop(txtlop.Text, ddlng); if (lopdao.addLOP(lp)) { Label1.Text = "DA THEM"; grvlop.DataSource = lopdao.getTalbe("select * from LOP "); grvlop.DataBind(); } else { Label1.Text = "ERROR Them"; } }