Solved

Linq to List of string not working

Posted on 2012-03-22
3
346 Views
Last Modified: 2012-03-22
hello ee,

i have this:    dim q = (From x in myTable Select x.Field(Of String)("CompanyNo")).Distinct()

wich reuslt as:

"01"
"02"
"00"

I have :   Dim list as new List(Of String)

Im trying:       list = q  
to fill my List with "01" "02" "00"

but i have error

how can I fill my list with q ?
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 37753310
Have you tried:

list = q.ToList()
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 37753365
Right (with respect to PaulHews). The "thing" returned by your query is defined by function you last called against the query (I'm speaking of Distinct in this case), or the query itself if you don't execute any function against it. The Distinct method returns back an IEnumerable(Of T), which is not a List(Of T). A IEnumerable(Of T) can be loaded or turned into a List(Of T), but it is not the same as a List(Of T). You can use the aforementioned ToList extension method to convert the IEnumerable(Of T) you get back from Distinct into a List(Of T).

* I'm using the generic terms "Of T". You are using String, so substitute String for T in the above description.
0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
ID: 37753376
thanks, actually I tried but went to fast and my toList() was placed at the wrong place.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now