public bool Insert(FirstAidKitBLL firstAidKit) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "INSERT INTO tbl_FirstAid (firstAid_no, Medical_Kit, Unit) VALUES (@firstAid_no, @Medical_Kit, @Unit)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@firstAid_no", firstAidKit.ID); cmd.Parameters.AddWithValue("@Medical_Kit", firstAidKit.MedicalKit); cmd.Parameters.AddWithValue("@Unit", firstAidKit.Unit); conn.Open(); int rows = cmd.ExecuteNonQuery(); // If the query is executed successfully then the value to rows will be greaten than 0 else it will be less than 0 if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Insert data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }
public bool Update(FirstAidKitBLL firstAidKit) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "UPDATE tbl_FirstAid SET Medical_Kit=@Medical_Kit, Unit=@Unit WHERE firstAid_no=@firstAid_no"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@Medical_Kit", firstAidKit.MedicalKit); cmd.Parameters.AddWithValue("@Unit", firstAidKit.Unit); cmd.Parameters.AddWithValue("@firstAid_no", firstAidKit.ID); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Update data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }