简体   繁体   中英

Is there a way to import data from an excel sheet into a SQL Server database?

Is there a way to import data from an excel sheet into a database on SQL Server without using the bulk method? Keeping in mind that I'm creating a web application where the user uploads an excel file to the page and it proceeds to import it into an existing database.

The bulk method works using OleDbDataReader, except it copies the excel sheet and pastes it onto the database without considering the column names compatibility. Am I missing something?

If you are working through SSMS, use the SQL Import Export Wizard. There's enough documentation on MSDN

From code you can use the SqlBulkCopy class for importing into SQL databases. If you are importing bulk records into Oracle you can use ODP.net OracleBulkCopy . Oracle bulk copying is only supported right now through the full ODP.net provider. Managed ODP.net does not support bulk operations.

To read the Excel file you can use any number of libraries.
LinqToExcel, OleDb, closedxml

Take a look at the DocumentFormat.OpenXml.Spreadsheet namespace: MSDN Link

It will let you look at the different parts of the spreadsheet as it is stored in OpenXML.

You can use format file along with bulk insert. The format file maps between table columns and the fields in the file.

Refer : https://docs.microsoft.com/en-us/sql/relational-databases/import-export/use-a-format-file-to-bulk-import-data-sql-server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM