string xConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("ExcelImport.xls") + ";" + "Extended Properties=Excel 8.0;";using (OleDbConnection connection = new OleDbConnection(xConnStr)) { 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 =DataAccess_Perf.GetConnectionString() ; // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "ImportedExcelData"; bulkCopy.WriteToServer(dr); } } }
Workbook workbook = new Workbook(); workbook.LoadFromFile(@"D:\michelle\my file\FandH.xlsx"); Worksheet sheet = workbook.Worksheets[0]; this.dataGridView1.DataSource = sheet.ExportDataTable();
Login to post response