Reputation: 497
I have the below code I am getting a distinct value from the datatables and then using the value to select on that datatable.
string ccId = d.ToString();
is being returned as "{ id = B08 }" -- I just need B08 how can I get that value?
var distinctIds = dt.AsEnumerable()
.Select(s => new { id = s.Field<string>("CCId"),})
.Distinct().ToList();
foreach (var d in distinctIds)
{
string ccId = d.ToString();
DataTable selectedTable = dt.AsEnumerable()
.Where(r => r.Field<string>("CCId") == ccId).CopyToDataTable();
CreateFile(selectedTable);
}
Upvotes: 0
Views: 42
Reputation: 2738
You are forcing this structure when populating distinctIds
. By removing the anonymous (new) call in your select you will have a list of the values only.
var distinctIds = dt.AsEnumerable()
.Select(s => s.Field<string>("CCId"))
.Distinct().ToList();
Upvotes: 3