Solved

Help with Linq To Dataset

Posted on 2014-10-24
2
170 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

16 Experts available now in Live!

Get 1:1 Help Now