I am trying to grab unique values from a DataTable Column into a list. The table & column name (plus potentially type) will vary with each usage of the function. How do I change the data type for the group by line using variables (or other).
private IEnumerable<string> GetSeparateParent(DataColumn parentAlpha)
{
DataTable dt = parentAlpha.Table;
string fieldName = parentAlpha.ColumnName;
IEnumerable<string> parent;
Type ColumnType = parentAlpha.DataType;
parent = from a in dt.AsEnumerable()
group a by a.Field<ColumnType>(parentAlpha) into g
select new
{
Alpha = g.Key.ToString()
};
return parent;
}
ANy suggestions?