Archive
Posts Tagged ‘SQLBulkCopy Example’
How to implement SQL Bulk Copy in SQL Server OR Bulk insert into SQL Server using SQL BulkCopy
SqlBulkCopy for insert multiple rows of data into table in SQL Server
Sometimes we need to insert bulk amount of data into a table in SQL. We can insert bulk data to SQL in different methods. Here we are going to demonstrate how to insert large amount of data using SQL Bulk Copy method.
Example of SQL BulkCopy method
Here we are going to insert multiple rows of sample data into Employee table. First of all create a table in SQL named Employee. After that create sample data for employee table and finally this multiple rows of employee data insert into table using SQL bulk copy method.
Create a Table in SQL
CREATE TABLE Employee ( ID INT, EmpName varchar(200), Department varchar(200), DOB DateTime );

SQLMulkCopy Example in SQL Server
C# Code to generate sample data and insertion using SQL Bulk Copy
private void loadDataBySQLBulkCopy() { DataTable dtTblEmployee = new DataTable(); dtTblEmployee.Columns.Add("ID", typeof(Int32)); dtTblEmployee.Columns.Add("EmpName", typeof(String)); dtTblEmployee.Columns.Add("Department", typeof(String)); dtTblEmployee.Columns.Add("DOB", typeof(DateTime)); DataRow dtrow = dtTblEmployee.NewRow(); // Create New Row dtrow["ID"] = 1; //Bind Data to Columns dtrow["EmpName"] = "Wazeem"; dtrow["Department"] = "Admin"; dtrow["DOB"] = "1990-10-16 12:00:00.000"; dtTblEmployee.Rows.Add(dtrow); dtrow = dtTblEmployee.NewRow(); // Create New Row dtrow["ID"] = 2; //Bind Data to Columns dtrow["EmpName"] = "Aslam"; dtrow["Department"] = "HR"; dtrow["DOB"] = "1987-05-16 12:00:00.000"; dtTblEmployee.Rows.Add(dtrow); dtrow = dtTblEmployee.NewRow(); // Create New Row dtrow["ID"] = 3; //Bind Data to Columns dtrow["EmpName"] = "John"; dtrow["Department"] = "Finance"; dtrow["DOB"] = "1992-12-11 12:00:00.000"; dtTblEmployee.Rows.Add(dtrow); dtrow = dtTblEmployee.NewRow(); // Create New Row dtrow["ID"] = 4; //Bind Data to Columns dtrow["EmpName"] = "Mishal"; dtrow["Department"] = "Infra structure"; dtrow["DOB"] = "1989-04-01 12:00:00.000"; dtTblEmployee.Rows.Add(dtrow); SqlBulkCopy bulkCopy = new SqlBulkCopy( "server=TEST;database=TEST;uid=test;password=test", SqlBulkCopyOptions.TableLock); bulkCopy.DestinationTableName = "dbo.Employee"; bulkCopy.WriteToServer(dtTblEmployee); }
Search other topic from here
Blog Stats
- 292,071 hits
Top Posts
Recent Posts
- How to access all types of server controls in ASP.Net using Javscript/JQuery OR Clear all server controls values using javascript or Jquery
- How to implement Cache mechanism in ASP.Net/C# using simple example OR What is Output Caching and Fragment Caching in ASP.Net/C#
- How to implement CAPTCHA image validation in ASP.Net/C# OR CAPTCHA image validator Sample in ASP.Net/C#
- How to implement SQL Bulk Copy in SQL Server OR Bulk insert into SQL Server using SQL BulkCopy
- How to merge two data tables in ASP.Net/C# OR Merge 2 DataTables and store in a new one in ASP.Net/C#
- How to implement Password validation in ASP.Net/C# OR Implement Password strength using Jquery in ASP.Net
- How to create breadcrumbs in ASP.Net/C# OR Show Navigations for each pages in ASP.Net/C# OR How to implement Sitemap in ASP.Net
- How to create a drag able and resizable div in ASP.Net/C# OR How to make a div Dragable and Resizable using Jquery in ASP.Net/C#
- How to implement BalloonPopupExtender in ASP.Net/C# OR Ballon Popup Extender Sample in ASP.Net/C#
- How to create always visible div using Ajax/ Always visible div in ASP.Net using Ajax
- Example for All Types of SQL JOIN (Inner Join, Cross Join, Outer Join, Self Join)
- How to Create a Data Table Dynamically with sample data and Bind to Grid/Create datatable with sample data.
Archives
- June 2013 (1)
- May 2013 (2)
- October 2012 (4)
- September 2012 (6)
- July 2012 (4)
- June 2012 (1)
- May 2012 (1)
- March 2012 (2)
- February 2012 (2)
- January 2012 (1)
- October 2011 (2)
- September 2011 (5)
- August 2011 (1)
- July 2011 (6)
- June 2011 (18)
- May 2011 (14)
Recent Comments