what is the best way to upload a csv file into a MS SQL table?
Several approaches:
- Use SQL Bulk Import Stored Proc and call the stored proc with the file path
- Use Sql开发者_开发技巧BulkCopy in System.Data.SqlClient dll
- Read the file line by line and then insert into a table row by row
- Any other ways?
Which one is best? I just want the user to select a file from asp.net webpage. And then click on Upload button to store the file in DB.
Secondly, do I need to move the file in server's memory before the file is copied into db table?
The DB won't know of the file because everything should be decoupled and layered. Saving the file to some shared location adds overhead and tidy ups etc
Yes
Surely you want this to be an atomic operation. 10k rows would be 10 round trips with a client side transaction running. If not atomic, then you'd need staging tables and tidy ups
Parse in c#, send to the DB with a table valued parameter. Otherwise, probably nothing same and/or realistic...
精彩评论