ASP. NET BULK Insert using SqlBulkCopy

Source: Internet
Author: User
Tags bulk insert

Bulk INSERT, I used to build a bunch of INSERT into SQL statements, and then use the program value row, to implement.

Today I saw ASP. You can use a DataTable, write data to a DataTable, and then use the SqlBulkCopy method to pass him a DataTable type, which automatically implements bulk insertions.

The speed is extremely fast.

Practice note here for future reference

    protected voidButton1_Click (Objectsender, EventArgs e) {            //prepare the data for bulk insertionDataTable table =NewDataTable (); Table. Columns.Add (" Age"); Table. Columns.Add ("Name"); DataRow Row=table.            NewRow (); row[" Age"] = -; row["Name"] ="Jack"; Table.            Rows.Add (row); DataRow Row1=table.            NewRow (); row1[" Age"] = in; row1["Name"] ="Fei"; Table.            Rows.Add (ROW1); stringConnectionStr ="server=.; database=demo;uid=sa;pwd=123456"; using(SqlBulkCopy bulkcopy =NewSqlBulkCopy (CONNECTIONSTR)) {Bulkcopy.destinationtablename=" Person";//in the inserted target table//Mapping of DataTable column names to database column namesBULKCOPY.COLUMNMAPPINGS.ADD (" Age"," Age"); BULKCOPY.COLUMNMAPPINGS.ADD ("Name","Name"); Bulkcopy.writetoserver (table);//writing to the database} Response.Write ("OK"); }    

ASP. NET BULK Insert using SqlBulkCopy

Related Article

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.