0

I have 1 Datagridview on Form1 and performing some calculations on it and have more than 20 columns. Now I want to update all columns values in the database when I click on the Update button.

For the calculation, I am using CellEndEdit events and it's working fine on multiple rows.

  • I'm going to presume that you haven't stored your data in a datatable; you should - especially because once you have done so you can probably get the datatable to perform some calculations for you - example `dt.Columns.Add("TotalPrice", typeof(double)).Expression = "[Quantity] * [UnitPrice]"` - a data adapter can still write these calculated columns to a database – Caius Jard Aug 08 '20 at 05:16
  • I am binding different data sources to datagridview according to condition. I also want to show calculation on datagridview columns and after on Update button click, changes will save into the database. – Monika Singh Aug 08 '20 at 16:09
  • As Caius mentions, if you need the columns to perform calculations based on a rows existing cell values, then a `DataTable`’s “Expression” column can make things much easier. You should clarify how the data is initially organized, is it a `DataTable`, `DataSet`, `List`…? – JohnG Aug 08 '20 at 19:32
  • Also, I have to ask, if you have columns that are “calculations” from the “existing” data in the grid, then updating those calculations when the values in the grid change makes sense… however… I would think that you would NOT want to save those calculations to the DB. Is there some reason you want to save these “computed” values to the DB? – JohnG Aug 08 '20 at 19:32

1 Answers1

0

If I are using some kind of mapping like Entity u can send the DataGridView to a function to iterate the rows and create a list of the objects then update them with the property context.table(lists).state =Entry.Modified

How to update record using Entity Framework 6?