Database db =databasefactory.createdatabase (); using(SqlConnection connection =(SqlConnection) db. CreateConnection ()) {Try{connection. Open (); stringTableName ="bg_payment_details"; using(SqlBulkCopy bulk =NewSqlBulkCopy (Connection, sqlbulkcopyoptions.keepidentity,NULL) {DestinationTableName=TableName, BatchSize=10000 }) { foreach(DataColumn DCinchdspayment.tables[1]. Columns) {bulk. Columnmappings.add (DC. ColumnName, DC. ColumnName); } bulk. WriteToServer (dspayment.tables[1]); Bulk. Close (); } } Catch(Exception exp) {Throwexp; } finally{connection. Close (); } }
View Code
Code as above, is actually relatively simple, is the local assignment of a good table, and then corresponding to the target table on the server, directly using the above program is OK.
DataTable directly to the server's table.
But there is also a pit over there, and a service must be opened on both sides.
Refer to the following page
http://www.lmwlove.com/ac/ID1144
Network access to the Distributed transaction Manager (MSDTC) is disabled in Win7. Use the Component Services Administration tool to enable DTC for network access in the MSDTC security configuration. "
Because the TransactionScope object was used in the program, the test reported that network access to the Distributed transaction Manager (MSDTC) was disabled. Use the Component Services Administration tool to enable DTC for network access in the MSDTC security configuration . "The error, I am the Win7 system, the solution is as follows:
Open Control Panel-> Administrative Tools-> Component Services such as:
Then double-click Computer-> My Computer-> Distributed Transaction Coordinator, then right-click Local DTC, select the Properties option, and set the following on the Security tab:
Large-volume data import in C #