I have a problem when trying to insert a .csv
file using bulk insert into SQL Server.
Csv file example rows at below:
16777216,16777471,AU,AUSTRALIA,APNIC DEBOGON PROJECT
16777472,16778239,CN,CHINA,CHINANET FUJIAN PROVINCE NETWORK
16778240,16779263,AU,AUSTRALIA,LEVEL 5 530 COLLINS STREET
This is my code:
CsvReader csv = new CsvReader(new StreamReader(fileName), false, ',', '\0', '\0', '\0', LumenWorks.Framework.IO.Csv.ValueTrimmingOptions.All);
csv.DefaultParseErrorAction = ParseErrorAction.AdvanceToNextLine;
csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;
copy = new SqlBulkCopy(conn, SqlBulkCopyOptions.KeepIdentity, transaction);
copy.DestinationTableName = "Blabla";
var mapping1 = new SqlBulkCopyColumnMapping(0, "ipFrom");
copy.ColumnMappings.Add(mapping1);
var mapping2 = new SqlBulkCopyColumnMapping(1, "ipTo");
copy.ColumnMappings.Add(mapping2);
var mapping3 = new SqlBulkCopyColumnMapping(2, "countryCode");
copy.ColumnMappings.Add(mapping3);
var mapping4 = new SqlBulkCopyColumnMapping(3, "countryName");
copy.ColumnMappings.Add(mapping4);
var mapping5 = new SqlBulkCopyColumnMapping(4, "isp");
copy.ColumnMappings.Add(mapping5);
copy.WriteToServer(csv);
transaction.Commit();
Result table is:
"16777216 16777471 AU AUSTRALIA APNIC DEBOGON PROJECT" "16777472 16778239 CN CHINA CHINANET FUJIAN PROVINCE NETWORK" "16778240 16779263 AU AUSTRALIA LEVEL 5 530 COLLINS STREET"
I can't handle this file line by line because file has approximately 100 million lines
How can I discard at the end and start double quotes?
you can use this code :