Public BOOLMssqlbulkcopydata (DataTable DT,stringconnectionString) { BOOLresult; Try { using(SqlConnection conn =NewSqlConnection (connectionString)) {Conn. Open (); SqlTransaction Trans=Conn. BeginTransaction (); SqlBulkCopy SqlBulkCopy=NewSqlBulkCopy (conn, Sqlbulkcopyoptions.default, trans); Sqlbulkcopy.destinationtablename=dt. TableName; Sqlbulkcopy.bulkcopytimeout= +; foreach(DataColumn Dtcolumninchdt. Columns) {sqlbulkCopy.ColumnMappings.Add (Dtcolumn.columnname, Dtcolumn.columnna ME); } Try{sqlbulkcopy.writetoserver (dt); Trans.commit (); Result=true; } Catch{trans. Rollback (); Sqlbulkcopy.close (); Result=false; } finally{sqlbulkcopy.close (); Conn. Close (); } } } Catch(Exception e) { This. Logger.writelog ("-----------Use net sqlbulkcopydata batch Import database, super fast-----------\ r \ n"+ E.message +"\ r \ n"); Result=false; } returnresult; }
Bulk Import Database