标题:从SQL2005中向listbox中添加数据
取消只看楼主
guojun1119
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2012-9-9
结帖率:76.92%
已结贴  问题点数:5 回复次数:1 
从SQL2005中向listbox中添加数据
从SQL sever 2005中向listbox中添加数据表中的一列名字Name,但是名字不重复添加到listbox中,如下代码应该怎么修改?
           this.LstAll1.Items.Clear();
            SqlConnection conn = new SqlConnection("Data Source=WANGHUI\\SQLEXPRESS;Initial Catalog=DB_Hyg;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("select *from Hydrochemistry", conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                if (!this.LstAll1.Items .Contains("?"))

                {
                LstAll1.Items.Add(sdr["Name"].ToString().Trim());
                }
            }
            sdr.Close();
            conn.Close();
搜索更多相关主题的帖子: 数据表 
2012-09-20 10:57
guojun1119
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2012-9-9
得分:0 
回复 3楼 ZWYyj
        private void frmPara_Load(object sender, EventArgs e)
        {
            this.LstAll1.Items.Clear();
            SqlConnection conn = new SqlConnection("Data Source=WANGHUI\\SQLEXPRESS;Initial Catalog=DB_Hyg;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT  * FROM Hydrochemistry", conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                if (!this.LstAll1.Items .Contains("?"))

                {
                LstAll1.Items.Add(sdr[" Name"].ToString().Trim());
                }
            }
            sdr.Close();
            conn.Close();
        }
我现在的问题是让Name这一列不重复的显示!
2012-09-27 16:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-381726-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051083 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved