删除数据库dulicate值

删除数据库dulicate值

本文介绍了删除数据库dulicate值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

如何从数据库中选择项目时删除重复值。此代码工作正常,但它在组合框中显示重复值。

喜欢:金色,金色,金色,银色,银色

它在组合框中显示3和2次。所以如何删除这个错误。

它只显示一次 -



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.

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; }
            }
        }

推荐答案

SELECT DISTINCT cmbItemType FROM ItemTable


这篇关于删除数据库dulicate值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 23:47