开发者

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

开发者 https://www.devze.com 2023-04-03 00:20 出处:网络
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.

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开发者_StackOverflow 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消