public bool Update(OrdersBLL sales) { bool isSuccess = false; SqlConnection conn = new SqlConnection(GlobalConfig.CnnString(db)); try { string sql = "UPDATE Orders SET SKU=@SKU, ProductName=@ProductName, Price=@Price, Quantity=@Quantity, Total=@Total, DatePurchased=@DatePurchased WHERE Id=@Id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@SKU", sales.SKU); cmd.Parameters.AddWithValue("@ProductName", sales.ProductName); cmd.Parameters.AddWithValue("@Price", sales.Price); cmd.Parameters.AddWithValue("@Quantity", sales.Quantity); cmd.Parameters.AddWithValue("@Total", sales.Total); cmd.Parameters.AddWithValue("@DatePurchased", sales.DatePurchased); cmd.Parameters.AddWithValue("@Id", sales.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); }
public bool Delete(OrdersBLL sales) { bool isSuccess = false; SqlConnection conn = new SqlConnection(GlobalConfig.CnnString(db)); try { string sql = "DELETE FROM Orders WHERE Id=@Id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@Id", sales.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, "Delete data from Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }