public void CreateBatch(BatchDTO batchDTO, ClassDTO classDTO) { try { //insertion code connectionDB.OpenConnection(); string sqlQuery = "insert into Batch values('" + classDTO.CLASSNAME + "','" + classDTO.CLASSCODE + "','" + batchDTO.BATCH + "','" + batchDTO.BATCHSTD + "','0','" + batchDTO.BATCHSTD + "')"; connectionDB.ExecuteQueries(sqlQuery); connectionDB.CloseConnection(); MessageBox.Show("Batch added successfully to the database", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SqlException ex) { if (ex.Number == 2627) { //Violation of primary key. Handle Exception connectionDB.CloseConnection(); MessageBox.Show("Already Batch: "+batchDTO.BATCH+" exists under Class: "+classDTO.CLASSNAME+" \n Try a new name for batch", "Insertion Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void CreateBatch(BatchDTO batchDTO, ClassDTO classDTO) { try { //insertion code connectionDB.OpenConnection(); string sqlQuery = "insert into Batch values('" + classDTO.CLASSNAME + "','" + classDTO.CLASSCODE + "','" + batchDTO.BATCH + "','" + batchDTO.BATCHSTD + "','0','" + batchDTO.BATCHSTD + "')"; connectionDB.ExecuteQueries(sqlQuery); connectionDB.CloseConnection(); } catch (SqlException ex) { if (ex.Number == 2627) { //Violation of primary key. Handle Exception connectionDB.CloseConnection(); MessageBox.Show("You have already added batch " + batchDTO.BATCH + " under " + classDTO.CLASSNAME + ". Try a new one.", "Error.."); } } }