Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,
how to remove the duplicate value when its select item from the database. this code is working fine but its show duplicate value in the combobo.
like: gold, gold, gold, silver, silver
its show 3 and 2 times in the combobox. so how to remove this error.
it is show only one - one times.

C#
private void cmboItemType()    //for combobox 
        {
            string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100";
            SqlConnection conn = new SqlConnection(connstr);
            SqlCommand cmd = new SqlCommand("SELECT cmbItemType FROM ItemTable", conn);
            conn.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            ArrayList ItemStore = new ArrayList();
            
            while (sdr.Read())
            {
                ItemStore.Add(new AddValue(sdr.GetString(0)));
            }
            sdr.Close();
            conn.Close();
            cmbItemType.DataSource = ItemStore;
            cmbItemType.DisplayMember = "Display";
            
        }
        public class AddValue
        {
            private string Displaym;
         
            public AddValue(string Display)
            {
                Displaym = Display;
            }
            public string Display
            {
                get { return Displaym; }
            }
        }
Posted
Updated 7-Sep-13 5:50am
v2

1 solution

Write Query Like This:
SQL
SELECT DISTINCT cmbItemType FROM ItemTable
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900