c# - How to insert a column with a specific value in sql bulk copy -
i populating table values in excel using sql bulk copy in c#.
datatable dt = new datatable(); string line = null; int = 0; using (streamreader sr = file.opentext(@"c:\temp\table1.csv")) { while ((line = sr.readline()) != null) { string[] data = line.split(','); if (data.length > 0) { if (i == 0) { foreach (var item in data) { dt.columns.add(new datacolumn()); } i++; } datarow row = dt.newrow(); row.itemarray = data; dt.rows.add(row); } } } using (sqlconnection cn = new sqlconnection(configurationmanager.connectionstrings["consoleapplication3.properties.settings.daasconnectionstring"].connectionstring)) { cn.open(); using (sqlbulkcopy copy = new sqlbulkcopy(cn)) { copy.columnmappings.add(0, 0); copy.columnmappings.add(1, 1); copy.columnmappings.add(2, 2); copy.columnmappings.add(3, 3); copy.columnmappings.add(4, 4); copy.destinationtablename = "censis"; copy.writetoserver(dt); } } in above code, inserting records excel table. but, have 1 more column "processid" in censis table. each time run, need generate guid , populate column this.
can 1 me how populate processid column when bulk copy above generated guid rows run?
when insert database use function newsequentialid
Comments
Post a Comment