Solved

Help with Linq To Dataset

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

820 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