Quickest way to update a DataColumns values?

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have to update 500k rows in a DataTable for a single column. Is there any
quicker way to do this other than looping through the rows and doing
row[col] = val; ?

-Joe
 
No, but you might issue an UPDATE sql statement to database (if it fits your
scenario).
 
Ah, and disable databinding if your table is bound (reenable it after
change).
 
Hi Joe

At Frist, thanks for Miha's kindly Replay.:)

Sorry, Joe, as far as I know, I'm afraid that we should loop through all
rows to update each "DataRow" in "DataTable",because "DataTable" is just a
collection of "DataRows" in Memory.
But if your concern is efficiency of updating database, you can set
"UpdateBatchSize" property of "DataAdapter" to change the number of rows
that are processed in each round-trip to the server.
* Property "UpdateBatchSize" is new in the .NET Framework version 2.0.

Or if you just want to update with database, as Miha said, you can use an
UPDATE SQL statement to database directly. This is much faster than use
DataTable and DataAdapter.
The process is DbCommand->Database, not DataTable->DataAdapter->Database.

Hope this helps
& If anything is unclear, please feel free to let me know.

Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Hi Joe

I¡¯d like to know if anything is unclear.
If you have any questions, please free to post them in the community.

Wen Yuan
Microsoft Online Community Support
===============================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
===============================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top