{
using (TransactionScope scope = new TransactionScope())
{
OpenConnection();
using (SqlBulkCopy sbc = new SqlBulkCopy(sqlConn as SqlConnection))
{
//服务器上目标表的名称
sbc.DestinationTableName = tableName;
sbc.BatchSize = batchSize;
sbc.BulkCopyTimeout = copyTimeout;
for (int i = 0; i < dt.Columns.Count; i++)
{
//列映射定义数据源中的列和目标表中的列之间的关系
sbc.ColumnMappings.Add(dt.Columns[i].ColumnName, dt.Columns[i].ColumnName);
}
sbc.WriteToServer(dt);
flag = true;
scope.Complete();//有效的事务
}
}
}
catch (Exception ex)
{
throw ex;
}
return flag;
}
public void OpenConnection()
{
if (sqlConn.State == ConnectionState.Broken || sqlConn.State == ConnectionState.Closed)
sqlConn.Open();
}
public void CloseConnection()
{
sqlConn.Close();
}
#endregion
#region dispose method
/// <summary>
/// dispose接口方法
/// </summary>
public void Dispose()
{
}
5/13 首页 上一页 3 4 5 6 7 8 下一页 尾页 |