public void updateSalesStockDetails(DataTable salesTable, SalesData sale) { try { conn = new SqlConnection(connectionString); conn.Open(); foreach (DataRow row in salesTable.Rows) { SqlCommand comm = new SqlCommand("UPDATE stockDetails SET quantity = @Quantity, lastUpdatedDate = @UpdatedDate WHERE itemName = @ItemName", conn); comm.Parameters.AddWithValue("@ItemName", row["itemName"].ToString()); comm.Parameters.AddWithValue("@Quantity", row["quantity"].ToString()); comm.Parameters.AddWithValue("@UpdatedDate", sale.SalesDate); comm.ExecuteNonQuery(); } } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } }
public int executeSalesMaster(SalesData sale) { String query = "INSERT INTO salesMaster(invoiceID,customerName,date,sellingCenter,totalPrice,totalNoOfItems,transportation) VALUES (@InvoiceID,@CustomerName,@Date,@SellingCenter,@TotalPrice,@TotalNoOfItems,@Transportation)"; int affectedLines = 0; try { conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@InvoiceID", sale.InvoiceID); comm.Parameters.AddWithValue("@CustomerName", sale.CustomerName); comm.Parameters.AddWithValue("@Date", sale.SalesDate); comm.Parameters.AddWithValue("@SellingCenter", sale.SellingCenter); comm.Parameters.AddWithValue("@TotalPrice", sale.TotalPrice); comm.Parameters.AddWithValue("@TotalNoOfItems", sale.TotalItems); comm.Parameters.AddWithValue("@Transportation", sale.Transport.ToString()); conn.Open(); affectedLines = comm.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(affectedLines); }