Tutorials ADO.NET Core Tutorial

Bulk Insert — Complete Guide

Bulk Insert — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.

On this page

ADO.NET Core Tutorial · Lesson 19 of 100

Bulk Insert

FoundationsSQL & safetyProductionProjects

Foundations · 1 — Connections & CRUD · ~6 min · Module 2: CRUD Operations

What is this?

SqlBulkCopy loads many rows fast from a DataTable, reader, or IDataReader into a table.

Why should you care?

ShopNest catalog imports and warehouse feeds cannot insert row-by-row.

See it live — copy this example

Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.

using var bulk = new SqlBulkCopy(conn) { DestinationTableName = "StagingProducts" };
bulk.ColumnMappings.Add("Sku", "Sku");
bulk.ColumnMappings.Add("Name", "Name");
await bulk.WriteToServerAsync(table, ct);
Console.WriteLine("bulk done");

What happened?

  • Map columns explicitly.
  • Use a staging table then MERGE.
  • BatchSize helps huge loads.

Practice next

  1. Create StagingProducts.
  2. Fill DataTable.
  3. WriteToServerAsync.
  4. Set BatchSize = 1000.
  5. Enable FireTriggers carefully.

Remember

SqlBulkCopy for volume. Stage then MERGE. Map columns.

ShopNest catalog import

Merchant CSV → staging → Products.

Outcome: Minutes instead of hours.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
Use a DataAdapter to update the database. Set the InsertCommand,?
Short answer: UpdateCommand, and DeleteCommand properties of the DataAdapter to define how data changes should be applied to the database. Real-world example (ShopNest) Always pass order ids with parameters: cmd.Paramete…
Mid PDF Detailed
Use the DataAdapter's Update() method to push the changes back to the database. Example: SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter); // Automatically generates insert, update, delete commands DataSet dataset = new DataSet();
Short answer: dapter.Fill(dataset, "Customers"); // Modify data in the DataSet dataset.Tables["Customers"].Rows[0]["CustomerName"] = "New Name"; // Update the database with the mod…
Mid PDF Detailed
Call the Update method on the DataAdapter to sync changes. Example: // Assuming you already have a populated DataTable DataTable table = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Customers", connection); // Set commands for Insert, Update, and Delete
Short answer: dapter.UpdateCommand = new SqlCommand("UPDATE Customers SET CustomerName = @CustomerName WHERE CustomerID = @CustomerID", connection); dapter.UpdateCommand.Parameters.Add("@CustomerName"…
Junior PDF Detailed
What is ADO.NET?
Short answer: ADO.NET (Active Data Objects .NET) is a data access technology in the .NET framework that enables applications to interact with databases and other data sources. Explain a bit more It provides a set of clas…
Mid PDF Detailed
Memory Efficiency:?
Short answer: A DataReader is a forward-only, read-only cursor, meaning it streams data from the database and does not store the entire result set in memory. DataSet, on the other hand, loads the entire result set into m…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

ADO.NET Core Tutorial
Course syllabus

ADO.NET Core Tutorial

Module 1: ADO.NET Fundamentals
Module 2: CRUD Operations
Module 3: Stored Procedures
Module 4: Transactions and Error Handling
Module 5: Performance Optimization
Module 6: ASP.NET Core Integration
Module 7: Advanced Enterprise Topics
Module 8: Testing and Debugging
Module 9: Cloud and DevOps
Module 10: Real-World Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details