1 #regionUse SqlBulkCopy to BULK insert data from a DataTable into a database2 /// <summary>3 ///use SqlBulkCopy to BULK insert data from a DataTable into a database4 /// </summary>5 /// <param name= "strTableName" >the corresponding table name in the database</param>6 /// <param name= "Dtdata" >Data Set</param>7 Public Static voidSqlbulkcopyinsert (stringstrTableName, DataTable Dtdata,stringconnectionString)8 {9 stringConstr = connectionString;//Database connection StringTen One Try A { - using(SqlBulkCopy sqlrevdbulkcopy =NewSqlBulkCopy (CONSTR))//Reference SqlBulkCopy - { theSqlrevdbulkcopy.destinationtablename = strTableName;//the corresponding table name in the database -Sqlrevdbulkcopy.notifyafter = DtData.Rows.Count;//There are several rows of data -Sqlrevdbulkcopy.writetoserver (Dtdata);//Data Import Database -Sqlrevdbulkcopy.close ();//Close Connection + } - } + Catch(Exception ex) A { atMessageBox.Show (ex. Message +"The database processes the row. Sqlbulkcopyinsert"); - Throw(ex); - } - } - #endregion
250,000 rows of data will only take approximately 2 seconds. But this seems to only apply to SQL database, for SDE is not useful, for the time being unknown why?
DataTable batch storage in SQL database