Guest User

Untitled

a guest
May 26th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. // Connection String to Excel Workbook
  2. string excelConnectionString = @"Provider=Microsoft
  3. .Jet.OLEDB.4.0;Data Source=Book1.xls;Extended
  4. Properties=""Excel 8.0;HDR=YES;""";
  5.  
  6. // Create Connection to Excel Workbook
  7. using (OleDbConnection connection =
  8. new OleDbConnection(excelConnectionString))
  9. {
  10. OleDbCommand command = new OleDbCommand
  11. ("Select ID,Data FROM [Data$]", connection);
  12.  
  13. connection.Open();
  14.  
  15. // Create DbDataReader to Data Worksheet
  16. using (DbDataReader dr = command.ExecuteReader())
  17. {
  18. // SQL Server Connection String
  19. string sqlConnectionString = "Data Source=.;
  20. Initial Catalog=Test;Integrated Security=True";
  21.  
  22. // Bulk Copy to SQL Server
  23. using (SqlBulkCopy bulkCopy =
  24. new SqlBulkCopy(sqlConnectionString))
  25. {
  26. bulkCopy.DestinationTableName = "ExcelData";
  27. bulkCopy.WriteToServer(dr);
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment