How to import Excel data to SQL table in C# and VB.NET
EasyXLS™ library allows you to import Excel data to SQL tables. The data can be imported from an Excel sheet or from the active Excel sheet. The entire sheet data or only data from ranges of cells can be imported.
EasyXLS can be successfully used to also import large Excel files having big volume of data with fast importing time.
EasyXLS permits you to import Excel files without Excel installed, without OLEDB, without Interop or any other additional software installed.
The source code samples can be integrated in:
- ASP.NET web pages - Windows applications - Windows Forms (WinForms) - Console applications - Windows service applications - ASP.NET MVC web applications
// Create an instance of the class that imports Excel files
ExcelDocument workbook = new ExcelDocument();
// Import Excel file to DataSet
DataSet ds = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\\Samples\\Excel to SQL.xlsx");
' Create an instance of the class that imports Excel filesDim workbook AsNew ExcelDocument
' Import Excel file to DataSetDim ds As DataSet = workbook.easy_ReadXLSXActiveSheet_AsDataSet("C:\Samples\Excel to SQL.xlsx")
Import Excel to SQL Server, MySQL or any other database
Once the Excel data is imported to DataSet, the records can be processed and entered into database using INSERT, UPDATE or other SQL commands specific to SQL Server, MySQL, Oracle, MS Access or any other database.
EasyXLS enables you to import Excel data to SQL database either from the entire sheet or from a range of cells. Importing only a range of cells is a very useful option especially for large Excel files because it reduces the speed of the import process.
In order to import multiple cell ranges at once from Excel sheet, the range parameter must be passed to the method as union of ranges (multiple ranges separated by comma).
All the methods that allow importing Excel to DataSet have parameters that permit importing only ranges of cells.
Import XLSX, XLSB, XLSM and XLS files to SQL table