I am having some problems using LINQ to access Distinct records from a Dataset. I have looked around and believe it should be as simple as added
Expand|Select|Wrap|Line Numbers
- .Distinct()
My DataSet has multiple tables, all populated with data. I have a table called DemographicCriteria which has the fields listed below.
- CriteriaID
- DemographicCode
- InputID
- ExpressionID
- Value
CriteriaID is an autonumber, InputID and ExpressionID are foreign keys from other tables. What I am trying to do is get the distinct DemographicCodes from this table.
I am using the following code:
Expand|Select|Wrap|Line Numbers
- DataAccess.RawDataDS ds = DataAccess.RawDataDSManagement.RawData;
- DataTable demoCriteria = ds.Tables["DemographicCriteria"];
- IEnumerable<DataRow> query =
- (from row in demoCriteria.AsEnumerable()
- select row.Field<string>("DemographicCode"));
- foreach (DataRow row in query)
- {
- Console.WriteLine(row.Field<string>("DemographicCode"));
- }
Does anyone have any ideas?