从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();