David GodisTei

David GodisTei

  • 1.7k
  • 21
  • 1.9k

Subtracting sum from sum into another column

Nov 16 2023 7:06 PM

Dear Forum,

I am developing a sales app project from two related tables (i.e., Stocks and Sales)

I am having a GrossQty column that sums up records in the Qty column and GrossQtySold column sums up records in the QtySold column. Now, I want to subtract the GrossQtySold from the QtySold into the QtyAvailable column in the stock table.

The GrossQty and the QtyAvailable are in the Stocks table while the GrossQtySold is in the Sales table.

These are the codes I used to sum up records in both the tables: -

private void btnGrossCalcu_Click(object sender, EventArgs e)
{
  grossQtySoldTextBox.Text = (from DataGridViewRow row in drugSalesDataGridView.Rows
     where row.Cells[5].FormattedValue.ToString() != string.Empty
      select Convert.ToDecimal(row.Cells[5].FormattedValue)).Sum().ToString();
}

private void btnGross_Click(object sender, EventArgs e)
{
    grossQtyTextBox.Text = (from DataGridViewRow row in drugStockDataGridView.Rows
                            where row.Cells[6].FormattedValue.ToString() != string.Empty
                            select Convert.ToDecimal(row.Cells[6].FormattedValue)).Sum().ToString();
}

I will appreciate if someone would help me to achieve my goal successfully

Thanks


Answers (2)