I have a Static Dataset and i want to Distinct Records from this DataSet how is it possible?
Asked
Active
Viewed 4,861 times
1
-
Yep, please correct the title for searching purposes, ;-) – German Latorre Aug 20 '10 at 11:04
3 Answers
0
This link suggests this code to get distinct values from a DataTable:
DataTable distinctTable = originalTable.DefaultView.ToTable(true);
The "true" argument in ToTable() method means it gets distinct values.

German Latorre
- 10,058
- 14
- 48
- 59
0
As an alternative, you can also go the LINQ route by using the LINQ to DataSet extensions:
using System.Data;
class Program {
static DataTable dtPosts = new DataTable();
static void Main(string[] args) {
//some work here to fill the table, etc.
//select distinct rows, and only two fields from those rows...
var rows = (from p in dtPosts.AsEnumerable()
select new
{
Title = p.Field<string>("Title"),
Body = p.Field<string>("Body")
}).Distinct();
Console.WriteLine("Select distinct count = {0}", rows.Count());
Console.ReadLine();
}
}
Depends on what you want to do. Thought I add it to the thread. Hope it helps!

David Hoerster
- 28,421
- 8
- 67
- 102