C#关于数据库查询信息赋值到combobox 下拉框中

最近项目需要用到数据库去重,然后将不重复的信息赋值在combobox中,采用新dataset的方式,将其值读出,然后赋值在数组中,即可。具体代码如下所示:

public void CoPassData1(ComboBox cobox, string TableName,string segment)

        {
            cobox.Items.Clear();
            DataClass.MyMean MyDataClsaa = new WLS.DataClass.MyMean();
            string sqlStr = "select distinct " + segment + " from " + TableName;
            DataSet ds = MyDataClass.getDataSet(sqlStr, TableName);
            SqlDataReader MyDR = MyDataClsaa.getcom("select distinct " + segment + " from " + TableName);

            if (ds.Tables[0].Rows.Count > 0)
            {
                string[] array=new string[ds.Tables[0].Rows.Count];
                for(int i=0; i                 {
                    array[i] = ds.Tables[0].Rows[i][segment].ToString();
                    cobox.Items.Add(array[i]);
                }
            }

        }

你可能感兴趣的:(C#关于数据库查询信息赋值到combobox 下拉框中)