Click here to Skip to main content
14,733,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wish to build and application with c# that will upload a single csv file from different source and map it to about 4 tables in sql server database. Can some one help me pls...am really new in the whole stuff
Posted

This should be very simple to do and you have a whole bunch of options to do it.

1. The CSV will have a specific format, which will map to your tables.

1. First you need to decide how you will upload the CSV into an object structure which can be passed to the Sql Server. There are a bunch of options here
a. You can treat your CSV as a data source and upload it into a Data Set or object data source
b. You can write a custom DTO, parse the file manually and then convert it into your desired list of objects.

2. Next you will have to transfer this data in bulk to the SP or if you dont want to use a SP then call an insert query multiple times. Here you can use Table value parameters, Convert your entity to XML and send it for bulk update or insert one row at a time

Thats it...

In case you are not so hung up on C# then you may use SSIS wizards which will allow you to do the same job with drag and drops
   
You can do this from T-SQL using the below statement:

bulk insert [dbo].[Courses]
from 'C:\Courses.csv'
with (fieldterminator = ',', rowterminator = '\n')
go



For additional info go to: Import a CSV File to SQL Server
   

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