Sending manually created datatable to SQL server
-
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 !!
-
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 !!
I wouldn't use a
DataAdapter
orDataTable
. I'd just read the file and create theINSERT
statements directly and push it through aSqlCommand
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
-
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 !!
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