private void btnXoa_Click(object sender, EventArgs e) { String sql = "DELETE FROM nhanvien WHERE nhanvien.ID = " + ID_NHANVIEN; UpdatePresenter updatePresenter = new UpdatePresenter(this, sql); if (updatePresenter.getKiemtra() == true) { MessageBox.Show("Xóa thành công !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); XemNV("SELECT nhanvien.ID, phongban.TENPHONG, HOTEN, NGAYSINH, CMND, DIACHI, DIENTHOAI, QUOCTICH, LOAI_NV, LUONGNGAY, LUONGTHANG, BACLUONG, TONGLUONG FROM nhanvien, phongban WHERE (nhanvien.ID_PHONG = phongban.ID)"); reset(); } }
private void btnCapnhat_Click(object sender, EventArgs e) { //UPDATE table_name //SET column1 = value1, column2 = value2, ... //WHERE condition; int luongngay = int.Parse(txtLuongngay.Text); int luongthang = int.Parse(txtLuongthang.Text); int bacluong = int.Parse(txtBacluong.Text); int tongluong = 0; if (luongngay != 0) { tongluong = luongngay; } else { tongluong = luongthang * bacluong; } String sql = "UPDATE nhanvien " + "SET HOTEN = '" + txtHoten.Text + "'," + "NGAYSINH = '" + txtNgaysinh.Text + "'," + "CMND = '" + txtCMND.Text + "'," + "DIACHI = '" + txtDiachi.Text + "'," + "DIENTHOAI = '" + txtDienthoai.Text + "'," + "QUOCTICH = '" + txtQuoctich.Text + "'," + "LOAI_NV = '" + txtLoai.Text + "'," + "LUONGNGAY = '" + txtLuongngay.Text + "'," + "LUONGTHANG = '" + txtLuongthang.Text + "'," + "BACLUONG = '" + txtBacluong.Text + "'," + "TONGLUONG = '" + tongluong + "' " + "WHERE ID = " + ID_NHANVIEN; UpdatePresenter updatePresenter = new UpdatePresenter(this, sql); if (updatePresenter.getKiemtra() == true) { MessageBox.Show("Đã cập nhật !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } //try //{ // //This is my connection string i have assigned the database file address path // string MyConnection2 = "datasource=localhost;database=quanlynhanvien;port=3306;username=root;password=''"; // //This is my update query in which i am taking input from the user through windows forms and update the record. // //string Query = "update student.studentinfo set idStudentInfo='" + this.IdTextBox.Text + "',Name='" + this.NameTextBox.Text + "',Father_Name='" + this.FnameTextBox.Text + "',Age='" + this.AgeTextBox.Text + "',Semester='" + this.SemesterTextBox.Text + "' where idStudentInfo='" + this.IdTextBox.Text + "';"; // //This is MySqlConnection here i have created the object and pass my connection string. // MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); // MySqlCommand MyCommand2 = new MySqlCommand(sql, MyConn2); // MySqlDataReader MyReader2; // MyConn2.Open(); // MyReader2 = MyCommand2.ExecuteReader(); // MessageBox.Show("Data Updated"); // while (MyReader2.Read()) // { // } // MyConn2.Close();//Connection closed here //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} }