Private voidAddshuju_click (Objectsender, RoutedEventArgs e) {Stopwatch Wath=NewStopwatch (); Wath. Start (); for(inti =0; I <Ten; i++) { //Create a DataTable instanceDataTable data =NewDataTable (); //Fill Fielddata =getfiled (data); for(intCount = i *100000; Count < (i +1) *100000; count++) {DataRow R=data. NewRow (); r[1] =string. Format ("It 's wonderful-{0}", Count *i); r[2] =string. Format ("{0}","male"); r[3] =i; r[4] ="Chaoyang"; r[5] =DateTime.Now; Data. Rows.Add (R); } sqlhelp.sqlbulk (data); } wath. Stop (); MessageBox.Show ("insert Complete, shared time is +"+Wath. Elapsedmilliseconds); } //add fields that must be filled in PrivateDataTable getfiled (DataTable data) {data. Columns.addrange (Newdatacolumn[] {NewDataColumn ("Id",typeof(int)), NewDataColumn ("Name",typeof(string)), NewDataColumn ("Sex",typeof(string)), NewDataColumn (" Age",typeof(int)), NewDataColumn ("Address",typeof(string)), NewDataColumn ("Addtime",typeof(DateTime)}); returndata; }
//BULK Insert Public Static voidsqlbulk (DataTable dt) {varCon =NewSqlConnection (conect); SqlBulkCopy Bulk=NewSqlBulkCopy (con); //the name of the tableBulk. DestinationTableName ="xiao_student"; Bulk. BatchSize=dt. Rows.Count; Try{con. Open (); if(dt! =NULL&& dt. Rows.Count! =0) {bulk. WriteToServer (DT); } } Catch(Exception) {Throw; } finally{con. Close (); if(bulk!=NULL) {bulk. Close (); } } }
SQL Server Large Data volume BULK INSERT