public static void DoBulkCopy() { var cars = new List <Car>() { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar1" }, new Car() { Color = "Red", Make = "Volvo", PetName = "MyCar2" }, new Car() { Color = "White", Make = "VW", PetName = "MyCar3" }, new Car() { Color = "Yellow", Make = "Toyota", PetName = "MyCar4" }, }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); var dal = new InventoryDAL(); var list = dal.GetAllInventory(); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var car in list) { Console.WriteLine($"{car.CarId}\t{car.Make}\t{car.Color}\t{car.PetName}"); } }
public static void DoBulkCopy() { Console.WriteLine("***Do Bulk Copy***"); var cars = new List <Car>() { new Car() { CarId = 40, Color = "Blue", Make = "Honda", PetName = "MyCarl" }, new Car() { CarId = 41, Color = "Red", Make = "Volvo", PetName = "MyCar2" }, new Car() { CarId = 42, Color = "White", Make = "VW", PetName = "МуСагЗ" }, new Car() { CarId = 43, Color = "Yellow", Make = "Toyota", PetName = "MyCar4" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); var lst = Dal.GetAllInventory(); InitCars(); ShowAllCars(); }
// ------------------------------------------------------------------------- #endregion #region Executing Bulk Copies with ADO.NET // ------------------------ Executing Bulk Copies with ADO.NET ------------------------- // In cases where you need to load lots of records into the database, the methods shown so far would be rather // inefficient.SQL Server has a feature called bulk copy that is designed specifically for this scenario, and it’s wrapped // up in ADO.NET with the SqlBulkCopy class. public static void TestBulkCopyWithCustomDataReader() { Console.WriteLine(" ************** Do Bulk Copy ************** "); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar1" }, new Car() { Color = "Red", Make = "Volvo", PetName = "MyCar2" }, new Car() { Color = "White", Make = "VW", PetName = "MyCar3" }, new Car() { Color = "Yellow", Make = "Toyota", PetName = "MyCar4" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); InventoryDAL dal = new InventoryDAL(); var list = dal.GetAllInventory(); Console.WriteLine(" ************** All Cars ************** "); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var itm in list) { Console.WriteLine($"{itm.CarId}\t{itm.Make}\t{itm.Color}\t{itm.PetName}"); } Console.WriteLine(); }
public static void DoBulkCopy() { Console.WriteLine("----------Do Bulk Copy-----------"); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar" }, new Car() { Color = "Red", Make = "Volvo", PetName = "MyCar2" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); InventoryDal dal = new InventoryDal(); var list = dal.GetAllInventory(); Console.WriteLine("*************All cars***********"); Console.WriteLine("CarId\tMake\tColor\tPetName"); foreach (var car in list) { Console.WriteLine($"{car.Id}\t{car.Make}\t{car.Color}\t{car.PetName}"); } }
public static void DoBulkCopy() { Console.WriteLine("**** Do bulk copy********"); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar1" }, new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar2" }, new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar3" }, new Car() { Color = "Blue", Make = "Honda", PetName = "MyCar4" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); InventoryDAL dal = new InventoryDAL(); var list = dal.GetAllInventory(); Console.WriteLine("CarID\tColor\tMake\tPetName"); foreach (var item in list) { Console.WriteLine($"{item.CarId}\t{item.Color}\t{item.Make}\t{item.PetName}"); } Console.WriteLine(); }
public static void TestBulkCopy() { List <Car> cars = new List <Car>() { new Car { PetName = "Ray", Color = "Black", Make = "Hyundai" }, new Car { PetName = "Charge", Color = "Violet", Make = "Toyota" }, new Car { PetName = "Electro", Color = "Maroon", Make = "Ferrari" }, new Car { PetName = "Mark", Color = "Blue", Make = "Volvo" } }; ProcessBulkImport importer = new ProcessBulkImport("Data Source=CHIRAG-DESK\\SQLEXPRESS; Initial Catalog=AutoLot; Integrated Security=true"); importer.ExecuteBulkImport <Car>(cars, "Inventory"); Console.WriteLine("************* BULK IMPORT DONE *************"); }
public static void DoBulkCopy() { WriteLine("******* Do Bulk Copy *******"); var cars = new List <Car> { new Car() { Color = "Blue", Make = "Honda", PetName = "BulkCar1" }, new Car() { Color = "Red", Make = "Subaru", PetName = "BulkCar2" }, new Car() { Color = "White", Make = "VW", PetName = "BulkCar3" }, new Car() { Color = "Yellow", Make = "Toyota", PetName = "BlukCar4" } }; ProcessBulkImport.ExecuteBulkImport(cars, "Inventory"); Console.WriteLine("Bulk copy completed."); InventoryDAL dal = new InventoryDAL(); var list = dal.GetAllInventory(); Console.WriteLine(" ************** Display All Cars ************** "); Console.WriteLine("CarId\tMake\tColor\tPet Name"); foreach (var item in list) { Console.WriteLine($"{item.CarId}\t{item.Make}\t{item.Color}\t{item.PetName}"); } WriteLine(); }