How to get distinct Data from Dataset ( or) select distinct from dataset.

In some scenario select distinct data from the Dataset. Dataset provide an option to get distinct data from the dataset. I have database connection to connect my local database.


  SqlDataAdapter da = new SqlDataAdapter(“select empolyeename,Department,salary from employees inner
join department on  employees.deptid=department.deptid”
, con);

DataSet ds = new DataSet();

da.Fill(ds,“details”);


After fill the dataset we want to select distinct department from the dataset.For this use the DefaultView.ToTable()

 

GridView1.DataSource= dv.ToTable(true, “Department”);

GridView1.DataBind();

Advertisements