I have created a data table. It has 3 column Product_id, Product_name and Product_price Datatable table= new DataTable('Product'); table.Columns.Add('Product_id', typeof(int)); table. Jardine, after two months I got the time to get back to this, sorry for delay. Basically I have an update function that polls the server for new rows and updates the DataTable in.
- Update Rows In Datatable Copy Rows
- Data Table Maker Science Project
- Create A Data Table
- Data Table Maker
Active2 years, 7 months ago
How to update large table with millions of rows in SQL Server? Only in those cases where the final set of rows is equal to @BatchSize will this code run a final UPDATE affecting 0 rows. This migration could take a time and new rows with invalid data could be inserted during migration. So, firstly fix places where your rows adds. This method is used to work with the data in the row retrieved by the row() selector used. It can be used to get existing data, or set new data to be used for the row. Note that when used as a setter, this method sets the data to apply to the table, but does not update the table's internal caches of data until the draw() method is.
I have created a data table. It has 3 column Product_id, Product_name and Product_price
Now I want to find by index, and update that row.
say for e.g.
I want to change value of Product_name column to 'cde' that has the Product_id column value : 2.
Oz12314.8k2121 gold badges8787 silver badges142142 bronze badges
folkfolkUpdate Rows In Datatable Copy Rows
17833 gold badges44 silver badges1515 bronze badges
6 Answers
First you need to find a row with id 2 then change the name so:
You could also try these solutions:
Or:
TafariTafari2,04633 gold badges1414 silver badges2626 bronze badges
idursunidursun5,63411 gold badge3131 silver badges4848 bronze badges
Mohamed Islam FaresMohamed Islam Fares
If your data set is too large first select required rows by Select(). it will stop further looping.
Then loop through subset and update
e03050e03050
You can traverse through the DataTable like below and set the value
OR
Hope this helps
Zahir KhanZahir Khan
RahulRahul57511 gold badge1414 silver badges3939 bronze badges
Not the answer you're looking for? Browse other questions tagged c#datatable or ask your own question.
Active2 years, 6 months ago
I have a dataset with around 25 million rows. I am taking a subset of these rows and performing a function which works fine. However, what I then need to do is update the values in original dataset with new values while retaining the rest. I am sure this is straightforward but I just can't get my head around it.
This is a simplified version of what I am dealing with:
What I am after is the values in 'ALLOCATED' and 'ASSIGNED' from
sub_dt
to replace the 'ALLOCATED' and 'ASSIGNED' values in dt
based on the 'ID_CD' column. The output I would be after, based on my example, would still have 25 million rows but have 2,000 updated rows. Any help would be much appreciated. Thanks.ChrisChris
1 Answer
The answer provided by David Arenburg in his comment explains how to join the subset of modified data back into the original
data.table
.However, I wonder why the OP doesn't apply the changes directly in the original
data.table
by reference using a function which returns a list:With this function the subset of rows can be updated directly within the
data.table
:Benchmark
Due to memory limitations only a smaller data set with 2.5 million rows (instead of 25 million in the OP) is used.
Updating the
data.table
'in place' is much faster than creating a subset and later join. The copy operation is required to start every benchmark run with an unmodified version of dt
. Therefore, the copy operation is benchmarked as well.data.table
version 1.10.4 was used.Data Table Maker Science Project
Community♦
UweUwe26k77 gold badges5757 silver badges8282 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.