|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Quickest way to update a DataColumns values?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). -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Joe" <jbassking@noemail.noemail> wrote in message news:eUrGpKu7GHA.3960@TK2MSFTNGP05.phx.gbl... >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 > Ah, and disable databinding if your table is bound (reenable it after
change). -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Joe" <jbassking@noemail.noemail> wrote in message news:eUrGpKu7GHA.3960@TK2MSFTNGP05.phx.gbl... >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 > 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.) |
|||||||||||||||||||||||