C# - is there a way to stream a csv file into database?

bulkinsert bulk-load c# sqlbulkcopy

Question

I saw lots of articles talking about using SqlBulkCopy to copy content from csv into database, but they all need to load the data into a data table or data set.

this is no good for me, since i deal with large amount of data, and i dont have powerful machine.

is there a way to stream data from the csv into database?

Thanks

Accepted Answer

This article does show how to load the data directly to the database, without using a temp data table/ data set.

C# - CSV Import Export

Just look for the moethod SaveToDatabaseDirectly


Popular Answer

The simplest approach would probably be to read the CSV file line-by-line and execute an SQL INSERT command to add the data to the appropriate table in the database.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why