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. Visual Basic
  4. Sending manually created datatable to SQL server

Sending manually created datatable to SQL server

Scheduled Pinned Locked Moved Visual Basic
questiondatabasesql-serversysadminperformance
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.
  • D Offline
    D Offline
    DA_Loring
    wrote on last edited by
    #1

    Hi, I have an application that reads data from a text file into a datatable in the format required for a table in an SQL SErver 2005 database. My question is, having filled the table 'manually' in memory, how do I connect that table to the database and insert the information? Obviously I can do inserts for each row in the datatable, but there are around 30,000 rows so I am looking for a faster method as this can take some time. I understand that the dataadapter requires the insert command etc but 1) how do I get the table into the adapter and 2) does it know that these are new records? Any help would be very geatly appreciated.

    David Loring !! Keep Music Live !!

    C D 2 Replies Last reply
    0
    • D DA_Loring

      Hi, I have an application that reads data from a text file into a datatable in the format required for a table in an SQL SErver 2005 database. My question is, having filled the table 'manually' in memory, how do I connect that table to the database and insert the information? Obviously I can do inserts for each row in the datatable, but there are around 30,000 rows so I am looking for a faster method as this can take some time. I understand that the dataadapter requires the insert command etc but 1) how do I get the table into the adapter and 2) does it know that these are new records? Any help would be very geatly appreciated.

      David Loring !! Keep Music Live !!

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      I wouldn't use a DataAdapter or DataTable. I'd just read the file and create the INSERT statements directly and push it through a SqlCommand object. You can put multiple commands into a SqlCommand object - It is just a string of SQL after all.


      Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

      1 Reply Last reply
      0
      • D DA_Loring

        Hi, I have an application that reads data from a text file into a datatable in the format required for a table in an SQL SErver 2005 database. My question is, having filled the table 'manually' in memory, how do I connect that table to the database and insert the information? Obviously I can do inserts for each row in the datatable, but there are around 30,000 rows so I am looking for a faster method as this can take some time. I understand that the dataadapter requires the insert command etc but 1) how do I get the table into the adapter and 2) does it know that these are new records? Any help would be very geatly appreciated.

        David Loring !! Keep Music Live !!

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You may also want to checkout the SqlBulkCopy[^]class if you're using the .NET Framework 2.0 or above. Check to see if it'll fit your requirements first.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        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