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. Inserting SQLSever rows

Inserting SQLSever rows

Scheduled Pinned Locked Moved C#
csharpquestiondatabasedata-structures
3 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.
  • A Offline
    A Offline
    ABean
    wrote on last edited by
    #1

    What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.

    H A 2 Replies Last reply
    0
    • A ABean

      What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      BCP would definitely be the best way. You could write out the file and execute BCP on it. You could also use parameters inserts. Construct your SqlCommand with parameters for the fields. When enumerating over your ArrayList, set the SqlParameter.Value for each field and call SqlCommand.ExecuteNonQuery. BCP will probably be faster, though.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      • A ABean

        What is the easiest what to load 4000 rows into a SQLSever db from a C# program? The C# rows are in an ArrayList. And the "scheme" is very simple [string, date, decimal, decimal, integer]. I’m looping threw the array, right now, and doing an insert for each row but I’m wondering if there is some way I can do this in bulk? I think BCP would be overkill in this case, so, I'm just wondering if there is something in ADO.NET that might handle a "large" number if inserts.

        A Offline
        A Offline
        Andy Brummer
        wrote on last edited by
        #3

        You can also just batch the insert statements together and execute them all at once, or in smaller batches of 10 or so. Just seperate the statements with ;


        If you don't kill me you will only make me stronger That and a cup of coffee will get you 2 cups of coffee

        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