How do I import a CSV file into SQL?

aformde

New member
Joined
Nov 24, 2009
Messages
3
Programming Experience
3-5
I need to read a csv file daily and append it to an SQL table? How can I do this in VB.Net?
 
I wouldn't do it in VB.NET, it would be much easier to do it with an SSIS package (DTS package if you are still using SQL Server 2000 or earlier)
 
For reading a delimited file into a dataset such as a CSV file you can use the TextFieldParser (example of its use is in the help file). There is also many other options for reading the file and splitting up its fields to assign to rows in a dataset.

You can then either set up stored procedures for your insert commands and assign its source to your dataset or use sqlBulkCopy to write the dataset contents to your database. Transactions can be used in both of the above choices to roll back all of the records if for any reason some record fails to fully be inserted.
 
Back
Top