Blazor Server - SQLBulkCopy Excel data into SQL Server table

Cenk 956 Reputation points
2023-01-17T17:05:52.67+00:00

Hello folks,

I am working on a Blazor server application. There is a requirement to insert excel data (approx. 200000 records) into a table. Is there any tutorial that I can follow?

Thank you.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,161 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,386 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,708 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2023-01-17T19:10:12.9233333+00:00

    there is no builtin support for excel files. you will want to read the excel rows, buuild an array of datarows, then call the bluck copy. you probably want to do this in batches (1k - 10K rows), rather than read all at once.

    read excel file:

    [https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk

    write to sqlserver:

    [https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlbulkcopy.writetoserverasync?view=dotnet-plat-ext-7.0

    if the excel file is really a csv file, then you also have the option of copying the file to sqlserver and call the sqlserver bulk insert:

    [https://learn.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-ver16