#region 使用SqlBulkCopy批量插入数据
//参数dt,数据源datatable
//参数tableName,目标sqlserver数据表名称
public void ExecuteTransactionScopeInsert(DataTable dt, string tableName)
{
int count = dt.Rows.Count;
int copyTimeout = 600;
bool flag = false;
try
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
{
using (TransactionScope scope = new TransactionScope())
{
cn.Open();
using (SqlBulkCopy sbc = new SqlBulkCopy(cn))
{
//服务器上目标表的名称
sbc.DestinationTableName = tableName; <
//参数dt,数据源datatable
//参数tableName,目标sqlserver数据表名称
public void ExecuteTransactionScopeInsert(DataTable dt, string tableName)
{
int count = dt.Rows.Count;
int copyTimeout = 600;
bool flag = false;
try
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
{
using (TransactionScope scope = new TransactionScope())
{
cn.Open();
using (SqlBulkCopy sbc = new SqlBulkCopy(cn))
{
//服务器上目标表的名称
sbc.DestinationTableName = tableName; <