I want to extract items of the column in DataTable and put them in List.
This are my List and DataTable:
List<int> product1 = new List<int>();
DataTable table = this.IoC.Resolve<ISurveyResultsService>().GetProduct(studyYear, productName);
I want to loop through the DataTable and put elements in the list. I tried like this:
foreach (var row in table.Rows)
{
product.Add((int)row["StudyID"]);
}
I get an error "Cannot apply indexing with [] to an expression of type 'object'"
Any idea how to fix that as simple as possible?