Exemplo n.º 1
0
 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 = records.ToList()
         };
         try
         {
             bc.WriteToServer(dataReader);
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
         finally
         {
             CloseConnection();
         }
     }
 }
Exemplo n.º 2
0
        public static void ExecuteBulkImport <T>(IEnumerable <T> records, string TableName)
        {
            OpenConnection();

            using (SqlConnection conn = sqlConn)
            {
                SqlBulkCopy sqlBulk = new SqlBulkCopy(conn)
                {
                    DestinationTableName = TableName
                };

                var dataReader = new MyDataReader <T>(records.ToList());

                try
                {
                    sqlBulk.WriteToServer(dataReader);
                }
                catch (Exception)
                {
                    throw;
                }

                finally
                {
                    CloseConnection();
                }
            }
        }
Exemplo n.º 3
0
        public void ExecuteBulkImport <T>(IEnumerable <T> records, string tableName)
        {
            OpenConnection();
            SqlBulkCopy sbc = new SqlBulkCopy(connection)
            {
                DestinationTableName = tableName
            };

            MyDataReader <T> reader = new MyDataReader <T>(records.ToList());

            try {
                sbc.WriteToServer(reader);
            } catch (Exception ex) {
                Console.WriteLine("Error: {0}", ex.Message);
            } finally {
                CloseConnection();
            }
        }
Exemplo n.º 4
0
 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 ex) {
             // should do something here
             WriteLine($"Something bad happened.\n{ex.Message}");
         }
         finally
         {
             CloseConnection();
         }
     }
 }