简体   繁体   中英

How to Update the values from datatable to datagridview using C#?

I have a datatable ( dtAmount ) which has two columns [HeadID] and [Amount] and I also have a datagridview which has two columns [HeadID] , [Amount] and some other columns.

This datagridview has already been bound with a datasource and HeadID is filled with values but respective Amount is null. The HeadID in dtAmount has the respective values in [Amount] column and hence I want to update amount for respective head into datagridview using the values from dtAmount .

I would suggest you "Merge" function of the DataTable class as follows:

yourDataTable.Merge(dtAmount,true, MissingSchemaAction.Add);

// Merge the specified System.Data.DataTable with the current DataTable, indicating whether to preserve changes and how to handle missing schema in the current DataTable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM