Пример #1
0
        public static void ExecuteBulkCopy <T>(IEnumerable <T> records, string tableName)
        {
            OpenConnection();
            using (var connection = _sqlConnection)
            {
                var bc = new SqlBulkCopy(connection)
                {
                    DestinationTableName = tableName
                };

                var dataReader = new MyDataReader <T> {
                    Records = records.ToList()
                };
                try
                {
                    bc.WriteToServer(dataReader);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    CloseConnection();
                }
            }
        }
 public static void ExecuteBulkImport <T>(IEnumerable <T> records, string tableName)
 {
     OpenConnection();
     using (SqlConnection conn = _sqlConnection)
     {
         SqlBulkCopy bc = new SqlBulkCopy(conn)
         {
             DestinationTableName = tableName
         };
         var dataReader = new MyDataReader <T>(records.ToList());
         try
         {
             bc.WriteToServer(dataReader);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             throw;
         }
         finally{ CloseConnection(); }
     }
 }