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