Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How do i insert this on my database.i need exact codes

What I have tried:

C#
private void btnPay_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvOrder.Rows)
                row.Cells["Amount"].Value = Convert.ToDouble(row.Cells["Qty"].Value) * Convert.ToDouble(row.Cells["Price"].Value);



        }
Posted
Updated 2-Oct-21 4:25am
v2

Assuming you are using SQL Server, the recommended way is to use databinding.
Bind data to DataGridView Control - Windows Forms .NET Framework | Microsoft Docs[^]

SQL Server is not the easiest database to work with, if your needs are simple I would recommend LiteDB, see: best-databases-for-a-small-net-application[^]
 
Share this answer
 
v2
Comments
Ernest Jan Sandoval 2-Oct-21 2:32am    
Is there anayway i can contact you guys privately?i really need it now
RickZeeland 2-Oct-21 2:35am    
Sorry, I'm too busy with work right now, maybe someone else can help you.
Besides I stopped using SQL Server years ago, did not like it at all :)
To add to what Rick has said, you shouldn't use the displayed values anyway - they may not be accurate as they may have been rounded by the ToSstring operation. It's a much better idea to do this kind of calculation on the underlying DataTable (or collection) that holds the data that the DGV is displaying from. You can then databind that to the DB and things start to happen automatically.

But ... in this case, it's probably better not to do it at all, but to use a Computed Column in the DB instead: Specify Computed Columns in a Table - SQL Server | Microsoft Docs[^] That way, you don't take any extra space in yoru DB, and it is worked out for you when you fetch the data.
 
Share this answer
 
Comments
Ernest Jan Sandoval 2-Oct-21 2:32am    
Is there anyway i can contact you guys?
OriginalGriff 2-Oct-21 3:33am    
Why? We are communicating at the moment!
Dave Kreskowiak 2-Oct-21 11:55am    
Never ask anyone for their private contact information. You're not going to get it. Interactions happen here or they don't happen at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900