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. how transmit array elements to a table of database at once

how transmit array elements to a table of database at once

Scheduled Pinned Locked Moved C#
databasequestionsql-serversysadmindata-structures
5 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.
  • M Offline
    M Offline
    mahraja
    wrote on last edited by
    #1

    Hi I have 4 arrays which i want to insert them into 4 columns of a table of my sql server 2000 database, and it should be done at once, not inserting one by one. How can i do this?

    L W 2 Replies Last reply
    0
    • M mahraja

      Hi I have 4 arrays which i want to insert them into 4 columns of a table of my sql server 2000 database, and it should be done at once, not inserting one by one. How can i do this?

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

      Transactions :) http://en.wikipedia.org/wiki/Atomicity\_(database\_systems)

      1 Reply Last reply
      0
      • M mahraja

        Hi I have 4 arrays which i want to insert them into 4 columns of a table of my sql server 2000 database, and it should be done at once, not inserting one by one. How can i do this?

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        Easiest way is to create a stored procedure and pass the data as parameter to server side. This requires only single call to db.

        The need to optimize rises from a bad design. My articles[^]

        M 1 Reply Last reply
        0
        • W Wendelius

          Easiest way is to create a stored procedure and pass the data as parameter to server side. This requires only single call to db.

          The need to optimize rises from a bad design. My articles[^]

          M Offline
          M Offline
          mahraja
          wrote on last edited by
          #4

          I have read somewhere that I should use union all like this: use myDb insert into myTable (columnName1,columnName2...) select row1value1,row1value2... union all select row2value1,row2value2... union all . . . but I don't know how pass the arrays to the stored procedure and how perform these in a loop to add all array elements automatically...:confused:

          W 1 Reply Last reply
          0
          • M mahraja

            I have read somewhere that I should use union all like this: use myDb insert into myTable (columnName1,columnName2...) select row1value1,row1value2... union all select row2value1,row2value2... union all . . . but I don't know how pass the arrays to the stored procedure and how perform these in a loop to add all array elements automatically...:confused:

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Union is only usable in db when you combine several result sets. You cannot use it to pass arrays from client. I don't remember if you can pass table type parameter in sql server 2000. That would be a solution in your case. It's not automatic so you must program the insert loop inside the procedure. Another option is to use SqlBulkCopy class. Have a look at that also.

            The need to optimize rises from a bad design. My articles[^]

            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