C# Tutorial – Import data from Excel to SQL Server | FoxLearn
Articles,  Blog

C# Tutorial – Import data from Excel to SQL Server | FoxLearn


Welcome to FoxLearn In this tutorial, I’ll show you how to import data from excel file to sql server Open your form designer, then drag TextBox, Button, Label, Combobox and DataGridView from the visual studio toolbox to your winform Next, We will design a simple UI that allows you to select the excel file, then load data from the excel file to DataGridView based on the sheet name you selected from the Comboxbox Right-click on your project, then select Manage Nuget Packages Next, You need to install the ExcelDataReader library to your project This is a lightweight and fast library written in c# for reading Microsoft Excel files You need to add the click event handler to the Browse button allows you to select the excel file, then open and read all sheet data You can use the CreateReader method of the ExcelReaderFactory class to read the excel file Data that you read from excel file will be returned as DataSet Next, you need to read all table names in the DataSet, then add the table name to the Combobox You need to specify the table name you want to retrieve the data, then bind the data to the DataGridView You need to install Dapper Plus from the Manage Nuget Packages to your project Dapper Plus is a high efficient Bulk Actions (Insert, Update, Delete, and Merge) for .NET It supports SQL Server, SQL Azure, SQL Compact, MySQL and more To play the demo, you should create a new database, then copy the customer table from the Northwind database into your database We will create a customer class with properties that correspond to the data fields in the customer table It allows you to map between customer objects and customer tables You need to add a BindingSource to your DataGridView, then modify your code to allow you to map data between DataTable and Customer List. You can use the BulkInsert method to insert large amounts of data into sql server Thank you for watching this video and don’t forget to subscribe to my channel

10 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *