reading csv file into database

M

Mike P

Does anybody have a simple example of reading the contents of a CSV file
into a database table?
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

Is this SQL server you are working with? If so, you can use the
SqlBulkCopy class in .NET 2.0. If you are using .NET 1.1 and before (and
SQL Server still), then you can use the BULK INSERT command to quickly
insert the contents of the CSV file.

If you are not working with SQL Server, then you might want to create a
Data Transformation Services package which you can use to read the CSV file
and put it into your database.

Worse comes to worse, you can read the contents of the CSV file into a
DataSet (using the text provider for OLE DB) and then set the state of the
rows to new (using the SetAdded method on the DataRow, if you are using .NET
2.0, if using .NET 1.1, then you will have to create a new DataSet and add
the row to the new data set).

Once you do that, you can create a DataAdapter using your provider and
then update your database.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top