Bulk insert into SQL table from CSV using C# -
i need mass insert info sql
csv
file. in sql utilize command:
bulk insert inputtestdata 'd:\project\unittestprojct\rgtestingtooltestproject\nunittestproject\rgtesttooldb\inputtestdata.csv' ( codepage ='raw', rowterminator='\n', fieldterminator = '\t' )
the above command working , inserts info when using sql query analyzer, but, throws error when executed c#
using code given below :
stringbuilder builder = new stringbuilder(); builder.append("bulk insert " + objectname + " "); builder.append("'" + resourcefilepath + path.directoryseparatorchar + objectpath + "'"); builder.append(" with"); builder.append(" ("); builder.append(" rowterminator='\n',"); builder.append(" fieldterminator = '\t'"); builder.append(" )"); sqlhelper.executenonquery(transaction, commandtype.text, builder.tostring());
it throws error:
bulk load info conversion error (type mismatch or invalid character specified codepage) row 1, column 8 (isbaselinetest).
the query generated c# code working fine in sql
query analyzer :
bulk insert inputtestdata 'd:\project\unittestprojct\rgtestingtooltestproject\nunittestproject\\rgtesttooldb\inputtestdata.csv' ( rowterminator=' ', fieldterminator = ' ',codepage ='raw' )
please allow me know if have required csv
, sql
table structure
please help on above.
thanks in advance
i'm pretty sure have escape backslash's line , field terminators, since looks string converted them actual characters 0x10 , 0x09. think has
builder.append(" rowterminator='\\n',"); builder.append(" fieldterminator = '\\t'");
c# sql sql-server bulkinsert sqlbulkcopy
No comments:
Post a Comment