tags:

views:

42

answers:

1

Hi,

I have a single columned datatable inside a single tabled dataset.

I just want to convert this dataset to distinct rows. Here is my code, it gives compile error '.' expected. What am I doing wrong? (I tried adding the ., still same error). I know this is something stupidly obvious. PLZ Save me! ;)

Thanks much in advance!

Dim query = _
    From email In ds.Tables(0) _
    Select email.Field<string>("Email").Distinct()

EDIT: DOH! MIXING VB/C# SYNTAX HERE! I changed to (Of String) and it works... BUT NOW 'query' is an ienumerable collection of characters... not a datatable... so how do I convert back easily without manually doing a loop?? Plz advise!

+3  A: 

You are applying the Distinct method to each string, not the result of the query. As strings are collection of character, you can apply extension methods to them too.

Put parentheses around the query:

Dim query = _
  (From email In ds.Tables(0) _
  Select email.Field(Of String)("Email")).Distinct()
Guffa
result now gives me a '<distinctIterator>d_7a'1[System.String]... when I try to cast to list<string> or DataTable it throws invalid cast exception... ugh, i might as well stop wasting my time and just do the old dictionary unique route...!
dferraro
..but I wont give up, so please tell me what I'm doing so obviously wrong! thanks!
dferraro
hmm... I changed the return result of the function to query.ToList() and it casted properly to list(of string). Still not the datatable I want, but will work good enough...
dferraro
.. Ive tried query.Cast(DataRow)... and (dataTable)... both no work..
dferraro
You can't just turn it into a DataTable. You would have to create the DataTable and populate it with data from the query. Possibly a DataAdapter might be useful.
Guffa