private void btnThoat_Click(object sender, EventArgs e) { this.Close(); frmDSLop frm = new frmDSLop(Khoa_ID); frm.Show(); }
private void btnDSLop_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = KetNoi.str; con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; string TenKhoa; TenKhoa = cboDSKhoa.SelectedItem.ToString(); cmd.CommandText = "SELECT Khoa_ID FROM Khoa WHERE TenKhoa='" + TenKhoa + "'"; SqlDataReader rd; rd = cmd.ExecuteReader(); DataTable td = new DataTable(); td.Load(rd); string MaKhoa; MaKhoa = td.Rows[0][0].ToString(); con.Close(); this.Close(); frmDSLop frmDS = new frmDSLop(MaKhoa); frmDS.Show(); }
private void btnXoa_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = KetNoi.str; con.Open(); SqlCommand cmd = new SqlCommand(); SqlCommand cmd1 = new SqlCommand(); SqlCommand cmd2 = new SqlCommand(); SqlCommand cmd3 = new SqlCommand(); cmd.Connection = con; cmd1.Connection = con; cmd2.Connection = con; cmd3.Connection = con; cmd1.CommandText = "SELECT SinhVien_ID FROM SinhVien WHERE ID_Lop='" + MaLop + "'"; SqlDataReader rd; rd = cmd1.ExecuteReader(); DataTable td = new DataTable(); td.Load(rd); string MaSinhVien; if (td.Rows.Count == 0) { MaSinhVien = ""; } else { MaSinhVien = td.Rows[0][0].ToString(); } cmd2.CommandText = "DELETE FROM KetQua WHERE ID_SinhVien='" + MaSinhVien + "' "; cmd3.CommandText = "DELETE FROM SinhVien WHERE SinhVien_ID='" + MaSinhVien + "' AND ID_Lop='" + MaLop + "'"; cmd.CommandText = "DELETE FROM Lop WHere Lop_ID='" + MaLop + "'"; DialogResult result; result = MessageBox.Show("BẠN CÓ MUỐN XOÁ DỮ LIỆU KHÔNG?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { cmd2.ExecuteNonQuery(); cmd3.ExecuteNonQuery(); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("DỮ LIỆU ĐÃ ĐƯỢC XOÁ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Close(); frmDSLop frm = new frmDSLop(Khoa_ID); frm.Show(); } }
private void button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = KetNoi.str; con.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; string TenKhoa; TenKhoa = cboKhoa.SelectedItem.ToString(); cmd.CommandText = "SELECT Khoa_ID FROM Khoa WHERE TenKhoa='" + TenKhoa + "'"; SqlDataReader rd; rd = cmd.ExecuteReader(); DataTable td = new DataTable(); td.Load(rd); string MaKhoa; MaKhoa = td.Rows[0][0].ToString(); cmd.CommandText = "UPDATE Lop SET TenLop='" + txtTenLop.Text + "',ID_Khoa='" + MaKhoa + "' WHERE Lop_ID='" + MaLop + "'"; DialogResult result; result = MessageBox.Show("BẠN CÓ MUỐN SỬA LẠI DỮ LIỆU KHÔNG?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("SỬA DỮ LIỆU THÀNH CÔNG"); this.Close(); frmDSLop frm = new frmDSLop(Khoa_ID); frm.Show(); } }