Solved

Help with Linq To Dataset

Posted on 2014-10-24
2
173 Views
Last Modified: 2016-02-15
Experts, I am having trouble getting a column from my datatable using a linq query. I fill the datatable from an SQL query. The column is an integer type. I can use the linq queries just fine with string columns but cannot get it to work on integers.

Please Help...

Column Name is "rWidth".
Dim query as iEnumerable(Of Integer)
Dim iList as New List(Of Integer)

query = From w in ds.tables("dtRibbon")
               Select w.Field(Of Integer)("rWidth")
               Distinct

iList = query.ToList

Open in new window

0
Comment
Question by:Basicfarmer
2 Comments
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40403564
You are missing two constructs:
1) AsEnumerable. You can't query against the DataTable's Rows collection, since DataRowCollection doesn't implement IEnumerable<T>.
2) Distinct is a method call.
Modified query is shown below
query = (From w in ds.tables("dtRibbon").AsEnumerable()
               Select w.Field(Of Integer)("rWidth"))
               .Distinct()

Open in new window

0
 

Author Closing Comment

by:Basicfarmer
ID: 40407073
Thanks for the solution. Exactly what I was missing...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

932 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

10 Experts available now in Live!

Get 1:1 Help Now