Home All Groups Group Topic Archive Search About

Quickest way to update a DataColumns values?

Author
13 Oct 2006 4:12 PM
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

Author
14 Oct 2006 6:14 AM
Miha Markic [MVP C#]
No, but you might issue an UPDATE sql statement to database (if it fits your
scenario).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"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
>
Author
14 Oct 2006 6:15 AM
Miha Markic [MVP C#]
Ah, and disable databinding if your table is bound (reenable it after
change).

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"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
>
Author
16 Oct 2006 5:07 AM
WenYuan Wang
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.)
Author
19 Oct 2006 6:17 AM
WenYuan Wang
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.)

AddThis Social Bookmark Button