public void ImportData() { // Connection String to Excel Workbook string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\stagingserver\abc\UPLOAD\MyFile.xls;Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""; OleDbConnection xlConn = new OleDbConnection(excelConnectionString); OleDbCommand xlCommand = new OleDbCommand("select col1, col2 from [Sheet1$]", xlConn); xlConn.Open(); using(DbDataReader dr = xlCommand.ExecuteReader()) { using(SqlBulkCopy copyData = new SqlBulkCopy(MYConnectionString)) { copyData.DestinationTableName = "MY_TABLE"; copyData.WriteToServer(dr); copyData.Close(); } dr.Close(); dr.Dispose(); } xlCommand.Dispose(); xlConn.Close(); xlConn.Dispose(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)