using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace Window1
{
    public partial class Shopping : Form
    {
        public Shopping()
        {
            InitializeComponent();
        }        private void Shopping_Load(object sender, EventArgs e)
        {
                string connString = "server=WIN-8B49A4OVKBA\\SQLEXPRESS;database=Shop;uid=sa;pwd=19870409";
                SqlConnection connection = new SqlConnection(connString);
                string sql = string.Format("select type from shopping");
                try
                {
                    SqlCommand command = new SqlCommand(sql, connection);
                    connection.Open();
                    SqlDataReader datareader = command.ExecuteReader();
                    string type1;
                    while (datareader.Read())
                    {
                        type1 = (string)datareader["type"];
                        cboType.Items.Add(type1);
       
                    }
                }
                catch (Exception ex)
                {                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
         }
}
代码没问题,但是我的下拉菜单中显示好几个重复的,怎么解决重复的只显示一个?
因为我写的循环结构,所有所有的shopping表中的type字段的值都显示出来了,有好多重复的,怎么才能让重复的只显示
一个,用if结构判断么?条件怎么写?谢谢大家了