title: Import Excel file using .NET Core ASP.NET Web Application to SQL Server database
body: <p>I'm trying to import an Excel file into my code then transport it to a database using NET Core MVC web Application. I want to know any great libraries on Visual Studios and links that could be great help. Right now I'm using EPPlus version that grabs the data from the Excel file and converts it into a ToString.</p>
  <p>Here some code I'm working on most of the work is in method <strong>import</strong> When I try to set the database and model to used anything else then string types I get errors like:</p>
  <blockquote>
  <p>Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF</p>
  </blockquote>
  <p>I tried <code>int.Parse()</code> but keep getting error. I tried doing to SQL Server running <code>SET IDENTITY_INSERT [StudentsList-2].[dbo].[Student] ON;</code> it tells me command ran successfully but I keep getting the error when I run the program. Any help or links would be great!</p>
  <pre><code>using ImportExcel.Models;
  using Microsoft.AspNetCore.Http;
  using Microsoft.AspNetCore.Mvc;
  using OfficeOpenXml;
  using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.IO;
  using System.Linq;
  using Microsoft.Extensions.DependencyInjection;
  using System.Threading.Tasks;
  using Microsoft.EntityFrameworkCore;
  
  namespace ImportExcel.Controllers
  {
      public class HomeController : Controller
      {
          private readonly ApplicationDbContext _dbContext;
  
          public HomeController(ApplicationDbContext dbContext)
          {
             _dbContext = dbContext;
          }
          public IActionResult Index()
          {
              return View();
          }
          ***public async Task&lt;List&lt;Countries&gt;&gt; Import(IFormFile file)
          {
              var list = new List&lt;Countries&gt;();
              using (var stream = new MemoryStream())
              {
                  await file.CopyToAsync(stream);
                  using (var package = new ExcelPackage(stream))
                  {
  
                      ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
                      var rowcount = worksheet.Dimension.Rows;
                      var colcount = worksheet.Dimension.Columns;
  
                      for (int row = 2; row &lt; rowcount; row++)
                      {
                          list.Add(new Countries {
                              CountryId=worksheet.Cells[row,1].Value.ToString().Trim(),
                              CountryName = worksheet.Cells[row, 2].Value.ToString().Trim(),
                              TwoCharCountryCode = worksheet.Cells[row, 3].Value.ToString().Trim(),
                              ThreeCharCountryCode = worksheet.Cells[row, 4].Value.ToString().Trim()
                          });
                      }
                  }
              }
              //SaveDataToDb(list);
              _dbContext.Countries.AddRange(list);
              await _dbContext.SaveChangesAsync();
              
              return list;
              
  
          }***
  
         
  
          public IActionResult About()
          {
              ViewData[&quot;Message&quot;] = &quot;Your application description page.&quot;;
  
              return View();
          }
  
          public IActionResult Contact()
          {
              ViewData[&quot;Message&quot;] = &quot;Your contact page.&quot;;
  
              return View();
          }
  
          public IActionResult Privacy()
          {
              return View();
          }
  
          [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
          public IActionResult Error()
          {
              return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
          }
      }
  }
  </code></pre>