Example #1
0
        public void Insert(DbConnection conn, string tableName, DataTable sourceData, Dictionary<string, string> columnMappings = null, DataRowState state = DataRowState.Added)
        {
            SqlConnection sqlConn = conn as SqlConnection;
            Check(conn);

            using (SqlBulkCopyWrapper sqlBC = new SqlBulkCopyWrapper(sqlConn))
            {
                sqlBC.BatchSize = 10000;
                sqlBC.BulkCopyTimeout = 600;
                sqlBC.DestinationTableName = tableName;
                if (columnMappings != null && columnMappings.Count > 0)
                {
                    foreach (var item in columnMappings)
                    {
                        sqlBC.ColumnMappings.Add(item.Value, item.Key);
                    }
                }
                else
                {
                    foreach (var item in sourceData.Columns.Cast<DataColumn>())
                    {
                        sqlBC.ColumnMappings.Add(item.ColumnName, item.ColumnName);
                    }

                }
                sqlBC.WriteToServer(sourceData, state);
            }
        }
Example #2
0
        public void Insert(DbConnection conn, string tableName, DataTable sourceData, Dictionary <string, string> columnMappings = null, DataRowState state = DataRowState.Added)
        {
            SqlConnection sqlConn = conn as SqlConnection;

            Check(conn);

            using (SqlBulkCopyWrapper sqlBC = new SqlBulkCopyWrapper(sqlConn))
            {
                sqlBC.BatchSize            = 10000;
                sqlBC.BulkCopyTimeout      = 600;
                sqlBC.DestinationTableName = tableName;
                if (columnMappings != null && columnMappings.Count > 0)
                {
                    foreach (var item in columnMappings)
                    {
                        sqlBC.ColumnMappings.Add(item.Value, item.Key);
                    }
                }
                else
                {
                    foreach (var item in sourceData.Columns.Cast <DataColumn>())
                    {
                        sqlBC.ColumnMappings.Add(item.ColumnName, item.ColumnName);
                    }
                }
                sqlBC.WriteToServer(sourceData, state);
            }
        }