• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

C# Get Unique DataRows based on 2 columns

Hi..
I have a data taAble with 10 columns... I need to return a data table with the unique values based on COL 1 and COL2 .   Any ideas ?  Maybe Linq?   Need some code examples please.
0
JElster
Asked:
JElster
  • 2
  • 2
1 Solution
 
EyalCommented:
is that what you are looking for?

var query = (from x in datatable
                    select new(col1 = x.col1, col2 = x.col2)).distinct()

Open in new window

0
 
JElsterAuthor Commented:
I get cannot convert lamba to delegate type
0
 
nishant joshiTechnology Development ConsultantCommented:
0
 
JElsterAuthor Commented:
Need it just on 2 columns
0
 
EyalCommented:
try something like this...

public class smallclass(){
public smallclass(int col1,int col2){
this.col1 = col1;
this.col2 = col2;
}
 public int col1(){get;set;}
 public int col2(){get;set;}
}
var query = (from x in datatable
                    select new smallclass( x.col1, x.col2)).distinct()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now