Select Distinct Rows from a DataTable


In ADO.NET 2.0 there is a feature that allows you to create a new table containing the distinct entries from an existing table like below.

DataTable distinctTable = originalTable.DefaultView.ToTable( /*distinct*/ true)


It gets all the distinct rows from the original Table.
If you want only a single column we can use...

DataTable distinctTable = originalTable.DefaultView.ToTable( /*distinct*/ true, /*Column Name*/ "Col1")

Gopikrishna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment