C # SQL full table Insert

Source: Internet
Author: User

Description

(1) Part of table a data inserted into table B

(2) The DataAccess class is the underlying class placed under the DAL layer;

Da. Strconnection written in the DataAccess class;


Whole Table Insert Method

private void inserttable () {

DataAccess da = new DataAccess ();
String sql= "Select 0, Field 1, Field 2, Field 3: From Table A where maintop_id in ("+ Mainid +") ";

DataTable dt = new DataTable ();

DT = Dataaccess.getdataset (sql, FALSE, NULL).   Tables[0]; Put the query results in the table DT

using (SqlBulkCopy SQLBC = new SqlBulkCopy (da. Strconnection)) {

Volume of data inserted at one time

Sqlbc.batchsize = 100000;
The number of seconds agreed before the operation has expired before the timeout, assuming that the transaction is not committed and the data is rolled back. All copied rows are removed from the target table
Sqlbc.bulkcopytimeout = 60;

Set the Notifyafter property so that every 10,000 data is inserted. Call the corresponding event.
Sqlbc.notifyafter = 10000;
Sqlbc.sqlrowscopied + = new Sqlrowscopiedeventhandler ();
Set the table to be written in bulk
Sqlbc.destinationtablename = "Table B";
Bulk Write
Sqlbc.writetoserver (DT);
}

}


private static string strconnection = ""; Variable Record connection string

public string strconnection
{
get {return strconnection;}//return value of member variable _name
set {strconnection = value;}//The property setting value is represented by Valuekeyword. Save the value with _name!
}

diagram:

C # SQL full table Insert

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.