
How to Import this Excel Data Into Table

2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Mar 15, 2024, 2:14 AM EDT
Hi Sandeep Kumar,
To import Excel data into a table in Dot net, you can utilize the
ExcelDataReaderlibrary. First, install theExcelDataReaderpackage via NuGet Package Manager. Then, you can use the following code snippet to achieve this:using ExcelDataReader; using System.Data; using System.IO; // Read Excel file using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { using (var reader = ExcelReaderFactory.CreateReader(stream)) { var result = reader.AsDataSet(new ExcelDataSetConfiguration() { ConfigureDataTable = (_) => new ExcelDataTableConfiguration() { UseHeaderRow = true } }); DataTable table = result.Tables[0]; // Assuming data is in the first sheet // Now you can use the 'table' to insert data into your database table } }This code snippet reads an Excel file, extracts the data, and stores it in a DataTable.
You can read your data sheet-wise using custom code
Sandeep KumarRank #1,642 · 937 reputationPosted Mar 15, 2024, 3:51 AM EDT
pls anyone help me