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

David GodisTeiPosted Nov 17, 2023, 8:34 PM
Hi Amit,
The project is for desktop windows form, designed in Visual Studio 2019, connected to Microsoft SQL Server 2016, using system.data.sqlclient and configuration manager. There is a successful connection between the application and the server. I have also almost finished the development, except a code to extract record from one table to calculate records in the other table. I am really stucked. I wish to insert the codes from the two forms here for studying of the problem:
I will appreciate a help to fix the problem.
Thanks
Amit MohantyPosted Nov 17, 2023, 6:02 AM
Could you please specify whether the application in question is designed for Windows or if it's a web-based application? Additionally, how does this application interact with the database? Does it utilize a database context or any other methods for database interaction? Providing more information about the project will help others gain a better understanding of the problem or context.