I am trying to do a bulk insert with C#. I saw some simple code for the case when number of columns in source csv is same as destination table. I have a csv file which I want to insert into specific columns of a destination table. In my case, the number of columns in destination is greater than the those in csv file. I want to be able to map csv columns to destination columns. Is that possible with SqlBulkCopy
? If not, any other options ?
I am using .NET 3.5 and Visual Studio 2008
Source http://www.codeproject.com/Articles/439843/Handling-BULK-Data-insert-from-CSV-to-SQL-Server
StreamReader file = new StreamReader(bulk_data_filename);
CsvReader csv = new CsvReader(file, true,',');
SqlBulkCopy copy = new SqlBulkCopy(conn);
copy.DestinationTableName = tablename;
copy.WriteToServer(csv);