Created
May 28, 2010 12:45
-
-
Save snahor/417112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connection String to Excel Workbook | |
string excelConnectionString = @"Provider=Microsoft | |
.Jet.OLEDB.4.0;Data Source=Book1.xls;Extended | |
Properties=""Excel 8.0;HDR=YES;"""; | |
// Create Connection to Excel Workbook | |
using (OleDbConnection connection = | |
new OleDbConnection(excelConnectionString)) | |
{ | |
OleDbCommand command = new OleDbCommand | |
("Select ID,Data FROM [Data$]", connection); | |
connection.Open(); | |
// Create DbDataReader to Data Worksheet | |
using (DbDataReader dr = command.ExecuteReader()) | |
{ | |
// SQL Server Connection String | |
string sqlConnectionString = "Data Source=.; | |
Initial Catalog=Test;Integrated Security=True"; | |
// Bulk Copy to SQL Server | |
using (SqlBulkCopy bulkCopy = | |
new SqlBulkCopy(sqlConnectionString)) | |
{ | |
bulkCopy.DestinationTableName = "ExcelData"; | |
bulkCopy.WriteToServer(dr); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment