Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Update Large DataTable

Update Large DataTable

Scheduled Pinned Locked Moved C#
csharptutorialquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wayne Phipps
    wrote on last edited by
    #1

    I have a large DataTable (67,000 records) and I need to perform an operation on just one column. As an example, if I wanted to set all characters to upper case, I would consider using something like: foreach (System.Data.DataRow row in myDataTable.Rows) { string lower = row[ColumnNumber].ToString(); row[ColumnNumber] = lower.ToUpper(); } Having tested the above code, it takes approx 60mins to update the entire data table on a 1.3ghz PC with 256mb ram. Is there a more efficient method? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

    B R 2 Replies Last reply
    0
    • W Wayne Phipps

      I have a large DataTable (67,000 records) and I need to perform an operation on just one column. As an example, if I wanted to set all characters to upper case, I would consider using something like: foreach (System.Data.DataRow row in myDataTable.Rows) { string lower = row[ColumnNumber].ToString(); row[ColumnNumber] = lower.ToUpper(); } Having tested the above code, it takes approx 60mins to update the entire data table on a 1.3ghz PC with 256mb ram. Is there a more efficient method? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

      B Offline
      B Offline
      Bill Dean
      wrote on last edited by
      #2

      Couple things: Although I've never really tested it, I've heard anecdotally that foreach is not a very efficient way to do things. You can try for(int i=0;i < myDataTable.Rows.Count;i++) and then refering to myDataTable.Rows[i] inside of the loop. More significantly: I think you should reconsider pulling 67000 rows into your client application. If you need to change that large a chunk of data, doing it in SQL on the database server will likely be faster. Just my $0.02...Hope it helps, Bill

      W 1 Reply Last reply
      0
      • B Bill Dean

        Couple things: Although I've never really tested it, I've heard anecdotally that foreach is not a very efficient way to do things. You can try for(int i=0;i < myDataTable.Rows.Count;i++) and then refering to myDataTable.Rows[i] inside of the loop. More significantly: I think you should reconsider pulling 67000 rows into your client application. If you need to change that large a chunk of data, doing it in SQL on the database server will likely be faster. Just my $0.02...Hope it helps, Bill

        W Offline
        W Offline
        Wayne Phipps
        wrote on last edited by
        #3

        Thanks for your reply. I'll give it a try. Unfortunately I don't have much choice over pulling all that data in because it's been exported from a legacy system that used its own format for data storage. Basically we've got to pull it in before we can push it into something else more usefull. Weve developed this application because no SQL server or MS Access is available on the client PCs where data has to be manipulated. Its a case of "If it takes an hour, it takes an hour" but it would be great to reduce this as much as possible. I'm willing to try anything anyone can think of. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

        1 Reply Last reply
        0
        • W Wayne Phipps

          I have a large DataTable (67,000 records) and I need to perform an operation on just one column. As an example, if I wanted to set all characters to upper case, I would consider using something like: foreach (System.Data.DataRow row in myDataTable.Rows) { string lower = row[ColumnNumber].ToString(); row[ColumnNumber] = lower.ToUpper(); } Having tested the above code, it takes approx 60mins to update the entire data table on a 1.3ghz PC with 256mb ram. Is there a more efficient method? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          There are several things you could do. The DataTable is a damn heavy object which is relatively slow compared to other data structures. This is the price you pay for the complexity of the class. So your first thought should be about another datacontainer. If you have relationships to other tables, a primary key set or active views on the datatable: Remove them, make your operation and readd. This way many checks while you update your data will be left out. Also try to call BeginLoadData() and EndLoadData(). I dont know if it increses performance in updates (as it does while adding) but its worth a try.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups