Use ExcelReaderFactory to read excel
You can use the code below
VB.net Code
Dim stream As FileStream = File.Open("YouExcelFilePath.xls", FileMode.Open, FileAccess.Read) Dim excelReader As IExcelDataReader = ExcelReaderFactory.CreateBinaryReader(stream) Dim result As DataSet = excelReader.AsDataSet() excelReader.Close() result.Dispose()
C # code
FileStream stream = File.Open("YouExcelFilePath.xls", FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); DataSet result = excelReader.AsDataSet(); excelReader.Close(); result.Dispose();
Now use can perform bulk import using the Bulkcopy class.
or
create xml and send to database
or
Use OPENROWSET to read the excel file in the Stored Procedure and insert / update data.
Please follow the article below to implement it.
Read Excel in SQL Stored Procedure
source share