I am trying to get data from xml file and then filter using datatable.Select() to adding the values in combobox.
But I am getting duplicate values, so I need to apply DISTINCT sort. Tried dt1.DefaultView.ToTable but no luck. still its adding duplicate items also in combobox. below is the code snippet which I am using:
DataTable dt1 = XMLCategory.ds.Tables["AgencyInfo"];
DataRow[] foundRows;
foundRows = dt1.Select("AgencyRegion='" + cmbAgPr_Region.Text + "'");
DataTable dt2 = dt1.DefaultView.ToTable(true, "AgencyMarket");
for (int i = 0; i < foundRows.Length; i++)
{
cmbAgPr_Market.Items.Add(foundRows[i][1]);
}
Any help..
You can use LINQ with
GroupByto get distinct. Sample code below assumes you need to distinct in the column “columnName” withstringtype: