Friday, May 1, 2009

Select Distinct Rows from DataTable Without Linq.

We can select distinct rows from datatable by creating DataView. DataView Have different methods for sorting,searching etc. operations on datarows. DataView have a Method Called ToTable() which Creates and returns a new Datatable based on rows in an existing datatable.
Usind this method we can select distinct rows based on particular Column.. here is the code.

Gridview1.DataSource = dtNew.DefaultView.ToTable( true, "MondayDates"); Gridview1.DataBind();

dtNew Is Datatable which contains duplicate rows MondayDates column.
but it will binds only Distinct rows to Grid..
parameter true Specify that need to select distinct rows from table.
parameter MondayDates is the name of column on which distinct clouse should be applied.

Thats all.
Hope this will help you

Thanks