Reading data from excel and send to SQL Server using Asp.Net MVC 5 C# with LINQ if its possible

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Reading data from excel and send to SQL Server using Asp.Net MVC 5 C# with LINQ if its possible



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 :)





I think you have a lot more Googling to do. The answer is in Google.
– Hozikimaru
Aug 2 at 13:10





I've been looking for this since the beginning of the week, but the answer below solved my problem, thank you
– Leonardo
Aug 2 at 13:37




3 Answers
3



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.





thanks, i'll try :)
– Leonardo
Aug 2 at 12:33





that's work, thank so much
– Leonardo
Aug 2 at 13:32



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



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS