1

I have a Static Dataset and i want to Distinct Records from this DataSet how is it possible?

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
anjum
  • 2,363
  • 6
  • 28
  • 25

3 Answers3

0

See here: How to select distinct rows in a datatable and store into an array

Community
  • 1
  • 1
Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94
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