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. .NET (Core and Framework)
  4. Update Multiple rows in DataTable at once

Update Multiple rows in DataTable at once

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasetutorialquestionannouncementlearning
2 Posts 2 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.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Hello all, Want to know whether can update data in a DataTable with condition? (like where clause in Query) eg. in DataTable1 currently like this

    Col1 Col2 Col3

    007 a car
    007 b book
    012 a calendar
    012 b pencil
    012 c cup
    014 a mouse
    014 b phone
    055 a pen

    but, in Database '012' is already existed. Thus, I want to update '012' to be '012A' in DataTable and then use SqlBulkCopy to insert data into Database. After update DataTable1 will be as below

    Col1 Col2 Col3

    007 a car
    007 b book
    012A a calendar
    012A b pencil
    012A c cup
    014 a mouse
    014 b phone
    055 a pen

    Please suggest how to update this without looping through all rows in DataTable1. Thanks and best regards.

    L 1 Reply Last reply
    0
    • N Naunt

      Hello all, Want to know whether can update data in a DataTable with condition? (like where clause in Query) eg. in DataTable1 currently like this

      Col1 Col2 Col3

      007 a car
      007 b book
      012 a calendar
      012 b pencil
      012 c cup
      014 a mouse
      014 b phone
      055 a pen

      but, in Database '012' is already existed. Thus, I want to update '012' to be '012A' in DataTable and then use SqlBulkCopy to insert data into Database. After update DataTable1 will be as below

      Col1 Col2 Col3

      007 a car
      007 b book
      012A a calendar
      012A b pencil
      012A c cup
      014 a mouse
      014 b phone
      055 a pen

      Please suggest how to update this without looping through all rows in DataTable1. Thanks and best regards.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      naunt wrote:

      Please suggest how to update this without looping through all rows in DataTable1.

      There are no methods to update data in a DataTable in bulk AFAIK. You could, however, dump your datatable into a temporary table in Sql Server, do the update there, and merge after.

      Bastard Programmer from Hell :suss:

      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