Please share the code how get data from excel using c#.net framework.
Loading
Please share the code how get data from excel using c#.net framework.
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
Sachin SinghRank #66 · 26.2K reputationPosted May 26, 2022, 10:52 AM EDT
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted May 26, 2022, 6:29 PM EDT
Leon DRank #851 · 2.6K reputationPosted May 26, 2022, 9:23 PM EDT
Anoop Kumar SharmaRank #127 · 17.4K reputationPosted May 27, 2022, 12:49 AM EDT
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 28, 2022, 9:54 AM EDT
using System.Data; using System.Data.OleDb; namespace Data_Migration_Process_Creator { class Class1 { private DataTable GetDataTable(string sql, string connectionString) { DataTable dt = null; using (OleDbConnection conn = new OleDbConnection(connectionString)) { conn.Open(); using (OleDbCommand cmd = new OleDbCommand(sql, conn)) { using (OleDbDataReader rdr = cmd.ExecuteReader()) { dt.Load(rdr); return dt; } } } } private void GetExcel() { string fullPathToExcel = ""; //ie C:\Temp\YourExcel.xls string connString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=yes'", fullPathToExcel); DataTable dt = GetDataTable("SELECT * from [SheetName$]", connString); foreach (DataRow dr in dt.Rows) { //Do what you need to do with your data here } } } }Jignesh KumarRank #91 · 22.9K reputationPosted May 29, 2022, 12:43 AM EDT