DataTable batch storage in SQL database

Source: Internet
Author: User
Tags bulk insert import database

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.