• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • 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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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