Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LINQ help

LINQ help

LINQ help

How do I write LINQ to query against a Dataset for the below query.

select [Column 0], [Column 9] from [TABLE_1]
where [Column 0] = 'NY'
group by [Column 0], [Column 9]

My table contains records like:
[Column 0], [Column 9]
NY aaa
NY aaa
NY bbb
WI ccc

The target is to get after running the query, but using LINQ:
[Column 0], [Column 9]
NY aaa
NY bbb


RE: LINQ help

If you're not aggregating the data, are you using group by just to get a distinct set of values?

you could try something like this:

CODE --> C#

static void Main(string[] args)
    var results = (from d in GetData()
                    where d.Column0 == "NY"
                    select new { d.Column0, d.Column9}).Distinct();

    foreach (var item in results)
        Console.WriteLine(string.Format("{0} - {1} ", item.Column0, item.Column9));


public class TABLE_1
    public string Column0 { get; set; }
    public string Column9 { get; set; }

public static List<TABLE_1> GetData()
    List<TABLE_1> lst = new List<TABLE_1>();
    lst.Add(new TABLE_1() { Column0 = "NY", Column9 = "aaa" });
    lst.Add(new TABLE_1() { Column0 = "NY", Column9 = "aaa" });
    lst.Add(new TABLE_1() { Column0 = "NY", Column9 = "bbb" });
    lst.Add(new TABLE_1() { Column0 = "WI", Column9 = "ccc" });
    return lst;

more on linq here: 101 Linq Samples

good luck!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close