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. Database & SysAdmin
  3. Database
  4. Upate Multiple Rows using update query in sql

Upate Multiple Rows using update query in sql

Scheduled Pinned Locked Moved Database
databasetutorialhelpannouncement
6 Posts 6 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.
  • B Offline
    B Offline
    ballameharmurali
    wrote on last edited by
    #1

    Hello everyone, I query the db and I get a number of rows returned. They are displayed in a form with fields to be updated. I know how to do the update on a one by one basis. What I want to do is be able to update multiple rows at once. Let say for example 5 fields per row and 10 rows. There is something about arrays and loop thru it that I cannot get to work. Any help would be greatly appreciated. Thanks Murali

    M L D A 4 Replies Last reply
    0
    • B ballameharmurali

      Hello everyone, I query the db and I get a number of rows returned. They are displayed in a form with fields to be updated. I know how to do the update on a one by one basis. What I want to do is be able to update multiple rows at once. Let say for example 5 fields per row and 10 rows. There is something about arrays and loop thru it that I cannot get to work. Any help would be greatly appreciated. Thanks Murali

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I generally loop through a datatable and update each row individually, there are some articles around where an xml string is used to pass a collection of rows into the database for updating but I have never actually needed to use it.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • B ballameharmurali

        Hello everyone, I query the db and I get a number of rows returned. They are displayed in a form with fields to be updated. I know how to do the update on a one by one basis. What I want to do is be able to update multiple rows at once. Let say for example 5 fields per row and 10 rows. There is something about arrays and loop thru it that I cannot get to work. Any help would be greatly appreciated. Thanks Murali

        L Offline
        L Offline
        loyal ginger
        wrote on last edited by
        #3

        If the new values can be expressed by expressions, then you can use an update query to update multiple records and multiple fields. For example,

        Update MyTable Set Price=Price*1.05, ItemVolume=ItemVolume+100 Where Category='Electronics';

        Hope this helps. Happy programming!

        1 Reply Last reply
        0
        • B ballameharmurali

          Hello everyone, I query the db and I get a number of rows returned. They are displayed in a form with fields to be updated. I know how to do the update on a one by one basis. What I want to do is be able to update multiple rows at once. Let say for example 5 fields per row and 10 rows. There is something about arrays and loop thru it that I cannot get to work. Any help would be greatly appreciated. Thanks Murali

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          What language are you using for your front end? Some languages will support this. For example, Java supports batch updates so you can loop through all the entries setting the update parameters for each in turn, then do an executeBatch to do the lot in one go. (OK, before anyone points this out, not all JDBC drivers support this.) C# has something similar, although I've never used it myself. And if you can do it in C#, you can probably do it in VB.NET as well.

          C 1 Reply Last reply
          0
          • D David Skelly

            What language are you using for your front end? Some languages will support this. For example, Java supports batch updates so you can loop through all the entries setting the update parameters for each in turn, then do an executeBatch to do the lot in one go. (OK, before anyone points this out, not all JDBC drivers support this.) C# has something similar, although I've never used it myself. And if you can do it in C#, you can probably do it in VB.NET as well.

            C Offline
            C Offline
            Corporal Agarn
            wrote on last edited by
            #5

            If using T-SQL you can use a join to populate the table with the information.

            1 Reply Last reply
            0
            • B ballameharmurali

              Hello everyone, I query the db and I get a number of rows returned. They are displayed in a form with fields to be updated. I know how to do the update on a one by one basis. What I want to do is be able to update multiple rows at once. Let say for example 5 fields per row and 10 rows. There is something about arrays and loop thru it that I cannot get to work. Any help would be greatly appreciated. Thanks Murali

              A Offline
              A Offline
              Andy_L_J
              wrote on last edited by
              #6

              If you are using SQL 2008 you can use Table Value Parameters to acheive this: Table-Value Parameters in SQL Server 2008 - VB.NET[^] :-\

              I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

              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