Bulk Copy Operations in ADO.NET 2.0
Bulk copying of data from one data source to another data source is a new feature added to ADO.NET 2.0. Bulk copy classes provides the fastest way to transfer set of data from once source to the other.
The text of this article is not in this database — only its details are. The old site it was published on is gone, but the Internet Archive kept a copy: Bulk Copy Operations in ADO.NET 2.0
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

MaruthakumarPosted Oct 9, 2007, 1:37 AM
i use this same piece of code., to transfer data from excel to sqlserver. My excel sheets come with multiple worksheets., I supply to the reader names of the sheets dynamically. what happens is the first worksheet gets its data into the sqlserver. but fails for the second and others. in whatever combination i try, only one worksheet get in.. if i comment writetoserver, i am able to see all worksheet names.. what to do.. ?? kindly help its very urgent
SunileditedPosted Jun 7, 2007, 5:00 AMEdited Jun 7, 2007, 5:04 AM
I have used the following code: // Connection String to Excel Workbook string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\details.xls;Extended Properties=""Excel 8.0;HDR=YES;"""; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection); connection.Open(); // Create DbDataReader to Data Worksheet using (DbDataReader dr = command.ExecuteReader()) { // SQL Server Connection String string sqlConnectionString = "Data Source=ss1;Initial Catalog=sunil;Integrated Security=True"; // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "Employee1"; bulkCopy.WriteToServer(dr); } } } but this doesnt give the desired output. Can u provide me other code for importing data field wise?
SunileditedPosted Jun 7, 2007, 5:00 AMEdited Jun 7, 2007, 5:05 AM
I have used the following code: // Connection String to Excel Workbook string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\details.xls;Extended Properties=""Excel 8.0;HDR=YES;"""; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand("Select * FROM [Sheet1$]", connection); connection.Open(); // Create DbDataReader to Data Worksheet using (DbDataReader dr = command.ExecuteReader()) { // SQL Server Connection String string sqlConnectionString = "Data Source=ss1;Initial Catalog=sunil;Integrated Security=True"; // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "Employee1"; bulkCopy.WriteToServer(dr); } } } but this doesnt give the desired output. Can u provide me other code for importing data field wise?