Use SqlBulkCopy to import data to ms SQL Server

Source: Internet
Author: User

Insus. NET always uses the table type to import data into ms SQL Server. Refer to stored procedure parameters as DataTable http://www.cnblogs.com/insus/archive/2012/09/22/2698515.html. Today, I learned a SqlBulkCopy file to import data to ms SQL Server.
For example, read a node of XML at http://www.cnblogs.com/insus/p/3778256.htmlto import xmldata to the data warehouse. Let's take a look at the xml structure. It has two fields. Therefore, the database needs to create a table with the same structure as the xml. The two fields can be the same or different names as the imported Source Field.


In. aspx, add a GridView and a Button control to display and execute import events:

 

Bind xml data to the Gridivew control:

 

The button event first declares a DataTable variable, then loops through the GridView control, fills the data in the DataTable, connects the data, and specifies the target data table (#50 lines of code ), matching field (#52 ~ #53 ).


The last step is to open the connection, start writing to the database, and close the connection.
The following is a real-time operation Demonstration:

 

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.