private void blokir(string IdMhsOrPegawai, string rfid, string NamaMhs) { string errInsert = string.Empty; cKoneksi koneksi = new cKoneksi(); SqlConnection conn = new SqlConnection(koneksi.konekMsSql('3'));//konek ke sql server historyBlokir cQuery qr = new cQuery(); SqlCommand cmd = null; try { conn.Open(); cmd = new SqlCommand(qr.qInsertHistory(), conn); cmd.Parameters.AddWithValue("@id_pengguna", IdMhsOrPegawai); cmd.Parameters.AddWithValue("@rfid", rfid); cmd.Parameters.AddWithValue("@nama", NamaMhs); cmd.ExecuteNonQuery();//insert ke sql } catch (Exception ex) { errInsert = ex.Message; } finally { conn.Close(); conn.Dispose(); } //jika insert ke table history sukses, lanjut hapus rfid dari tblMhs if (errInsert == string.Empty) { string konekKe = null; string queryUse = null; string paramUse = null; if (rbMahasiswa.Checked == true)//konek ke simak { konekKe = "2"; queryUse = qr.qUpdateRfidNullByNim(); paramUse = "@STUDENTID"; } else if (rbPegawai.Checked == true)//konek ke payroll { konekKe = "4"; queryUse = qr.qUpdateRfidNullByIdPeg(); paramUse = "@id_pegawai"; } SqlConnection connMhsOrPeg = new SqlConnection(koneksi.konekMsSql(Convert.ToChar(konekKe))); SqlCommand cmdDelRfid = null; try { connMhsOrPeg.Open(); cmdDelRfid = new SqlCommand(queryUse, connMhsOrPeg); cmdDelRfid.Parameters.AddWithValue(paramUse, IdMhsOrPegawai); cmdDelRfid.ExecuteNonQuery();//insert ke sql } finally { connMhsOrPeg.Close(); connMhsOrPeg.Dispose(); } } }