Solved

Linq to List of string not working

Posted on 2012-03-22
3
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

628 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