DataClassesLINQ_SQLDataContext db = new DataClassesLINQ_SQLDataContext(); var data = from sel in db.CustomerTBLs select sel; DataTable dt = new DataTable(); if (data.Any()) { Type t = data.First().GetType(); foreach (PropertyInfo p in t.GetProperties()) { // Get the name of the prperty dt.Columns.Add(p.Name); } } int j = 0; foreach (var rowObj in data) { DataRow dr = dt.NewRow(); dt.Rows.Add(dr); dt.Rows[j][0] = rowObj.Id; dt.Rows[j][1] = rowObj.Customername; dt.Rows[j][2] = rowObj.Address; dt.Rows[j][3] = rowObj.Mobile; j = j + 1; } EmpModel em = new EmpModel(); em.ShowData = dt; return View(em); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)