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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted May 29, 2022, 4:43 AM
Jayraj ChhayaPosted May 28, 2022, 1:54 PM
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
}
}
}
}
Anoop Kumar SharmaPosted May 27, 2022, 4:49 AM
Leon DPosted May 27, 2022, 1:23 AM
Muhammad Imran AnsariPosted May 26, 2022, 10:29 PM
Sachin SinghPosted May 26, 2022, 2:52 PM