private void hien() { string sql = @"select *from TheLoai"; dtgvtheloai.DataSource = KetNoi.getTable(sql); }
private void btLuu_Click(object sender, EventArgs e) { if (validate()) { if (state == "insert") { string sql = @"INSERT INTO TheLoai(MaTheLoai,TenTheLoai) VALUES ('" + txtma.Text + @"' ,N'" + txtten.Text + @"' )"; if (KetNoi.Query(sql) != -1) { MessageBox.Show("Thêm thành công !"); } else { MessageBox.Show("Có lỗi trong quá trình thêm"); } } //end add else if (state == "update") { string sql = @"UPDATE [QLTV_LOAN].[dbo].[TheLoai] SET [TenTheLoai]=N'" + txtten.Text + @"' WHERE MaTheLoai= " + txtma.Text; if (KetNoi.Query(sql) != -1) { MessageBox.Show("Sửa thành công !"); } else { MessageBox.Show("Có lỗi trong quá trình Sửa"); } } hien(); dongtxt(); mobtn(); }//end validate if (state == "delete" && validate()) { string sql = @"DELETE TheLoai WHERE MaTheLoai = " + txtma.Text; if (KetNoi.Query(sql) != -1) { MessageBox.Show("Xóa thành công !"); } else { MessageBox.Show("Có lỗi trong quá trình Xóa"); } hien(); dongtxt(); mobtn(); } }