Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to store csv file in database?
Posted
Comments
AmitGajjar 25-Aug-12 7:48am    
your question is not clear, you also need to explain your purpose of storing csv file in database.

A csv file is just text. You can either store it as one string, or if you want it to have more meaning, you need to parse it and store the data in columns in a table. Either way, this is a very vague question, we have no idea what you WANT to do with this csv, or where you are stuck, or if you tried anything at all before asking us to do it for you.
 
Share this answer
 
Comments
AmitGajjar 25-Aug-12 7:47am    
5+ Correct, Although question is not clear you have given two options nicely.
I take it you're after storing the data not in a single text column but properly interpreted to separate columns. If this is true you can interpret the data either in your application or in the database.

For example you can read the CSV using File.ReadAllLines and then using string.Split, you can split the data on each row. After that you can store the data into proper tables and columns.

On the other hand you can do the splitting also in SQL Server, for example you can create a small stored procedure which would have a varchar parameter for the csv data and the procedure would essentially do the same things.

The third option could be that you read the file using SQL Server and insert the data directly from the CSV file to the tables. For this you could use OPENROWSET. For an example, see; http://www.databasejournal.com/features/mssql/article.php/10894_3331881_2[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900