Saturday, October 2, 2010

Get Distinct Values from theRepeated DataSet

Here the main requirement is to get the unique values from the dataset which have more repeated data.
Problem :In my dataset i am getting each country  name at 3 times... i need to display the country name  in dropdownlist only one country no repeated country name.
Solution: If you want get the unique values from the dataset you can use 
Syntax:       ToTable(bool distinct,Columns)

bool distinct is true or false---> If you want distinct values set as true else false

        private dataset GetallCountries()
           Session["Countries"] = ds;
            DataTable uniqueCountriesDS = ds.Tables[0].DefaultView.ToTable(true, "sta_cty_code");
            DataSet countries = new DataSet();
            return countries;

No comments:

Post a Comment