-2

Whats is the best way of getting a csv file from a directory and read the data in the file and insert the data to database?(My prefer language is VB.net, but I dont mind C#)

Diana
  • 283
  • 1
  • 7
  • 13
  • do you want to read data without storing the file on disk as in most of the cases we save the file on disk just to read the data from file which we can do by stream as well and avoid File IO cost, let me know if you need code to implement it – rajansoft1 Jun 03 '13 at 09:33
  • Check this link for reading .csv files. http://stackoverflow.com/questions/5282999/c-net-reading-csv-file – vijay Jun 03 '13 at 09:34
  • Which database? Oracle for example has external tables that do this. In SQL Server you can use a simple Integration package (SSIS). I should consider to write a custom program only after considering available DB tools. – Andrea Colleoni Jun 03 '13 at 09:38
  • Why did you tag the question with asp.net? Is the cvs file uploading from a client? – Emond Jun 03 '13 at 09:38
  • rajansoft1: Im not sure if I need to store the file, I just need to know the best way of doing this. Andrea Colleoni: the database is SQL Server – Diana Jun 03 '13 at 09:48

1 Answers1

2

Two ways: Bulk copy. http://msdn.microsoft.com/en-us/library/ms188365.aspx SqlBulkCopy Class: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Both are very fast

kostas ch.
  • 1,960
  • 1
  • 17
  • 30