-2

Sorry with my English

I have an input file where the user will upload an Excel File, 1st I need to scan the extension of the file (.xlsx or .xls), after reading data from it and save the data in SQL Server.

Abour scan a extension I have this:

var ext = Path.GetExtension(file.FileName);
var allowedExtensions = new[] { ".xlsx", ".xls" };
if(allowedExtensions.Contains(ext)){ //codigo }

Now, my biggest question is to read the file data and send it to SQL Server.

The table has these columns:

  • ID

  • Registro

  • Nome

  • Ativo

I'm a newbie in the area, if that's simple, sorry :)

Riddhi
  • 201
  • 1
  • 10
Leonardo
  • 1
  • 4

3 Answers3

0

so you can read this thread, here is solidly explained how you can read data from excel : http://csharp.net-informations.com/excel/csharp-read-excel.htm

and about storing this data in DB, you can crate model class with the properties you already showed to us and then fill this properties with the data from excel and than insert them in db.

AlexiAmni
  • 382
  • 1
  • 15
0

I recommend to use linktoexcel package method for that process. Its is easy and little code to get data from excel file. Please check this link and try it. Get all the values from excel file by using linqtoexcel

Good luck

anoj kattel
  • 1
  • 1
  • 4
0

You can also use "Aspose.Cells" from nuget https://www.nuget.org/packages/Aspose.Cells/ to extract the cell information and fill your own objects with values if your intention is not to render the .xls/.xlsx but to extract the information then add to the DB.