public class Sqlbulk {public static void inserttable (DataTable dt, String tabelname, DataColumnCollection dtcolum) {string Str= "";//Database connection string SqlConnection connn=new SqlConnection (str); Conn. Open (); Declare SqlBulkCopy, using release unmanaged resource using (SqlBulkCopy SQLBC = new SqlBulkCopy (conn)) {//A The amount of data inserted in the second batch sqlbc.batchsize = 1000; The number of seconds allowed before the operation completes before timing out, if the transaction is not committed, the data is rolled back, and all replicated rows are removed from the target table sqlbc.bulkcopytimeout = 60; Set the Notifyafter property so that the corresponding event is called when each 10,000 data is inserted. Sqlbc.notifyafter = 10000; Sqlbc.sqlrowscopied + = new Sqlrowscopiedeventhandler (onsqlrowscopied); Set the table to be written in bulk sqlbc.destinationtablename =tabelname; Customize the DataTable and database fields to correspond to the//sqlbc.columnmappings.add ("id", "tel"); SQLBC.COLUMNMAPPINGS.ADD ("name", "Neirong"); for (int i = 0; i < Dtcolum.count; i++) {sqlBC.ColumnMappings.Add (Dtcolum[i]. Columnname.tostring (), Dtcolum[i]. Columnname.tostring ()); }//Bulk write sqlbc.writetoserver (DT); } conn. Dispose (); }//Response time Event void Onsqlrowscopied (object sender, Sqlrowscopiedeventargs e) {//Response.writ E ("<br/> ok!"); } }
DataTable Import Database