[HttpPost]
public ActionResult Index(HttpPostedFileBase excelFile)
{
if (excelFile != null)
{
/* Snip for brevity. */
var ds = new DataSet();
adapter.Fill(ds, "results");
DataTable data = ds.Tables["results"];
var people = new List<Person>();
foreach (var row in data.Rows)
{
Person newPerson = new Person(){
Id = row?,
Name = row?,
LastName = row?,
DateOfBirth = row?
};
people.Add(newPerson);
}
return View();
}
return RedirectToAction("Error", "Upload");
}
How can I retrieve the information contained in my datatable? I’ve checked the MSDN docs but they seem to only display how to programatically create a new DataTable and not how to retrieve data.
Thank you for your time.
You can write
row.Field<DateTime>("DateOfBirth").