我想将数据库中的数据显示到listbox中,我是这样写的:
 SqlConnection lee = new SqlConnection("Data Source=.;Initial Catalog=supervcd;Integrated Security=True");
            lee.Open();
            string StuSQL;
            StuSQL = "select artist,album from product where cid =(select cid from category where name =  '" + comboBox1.SelectedItem.ToString() + "') group by artist,album";
            SqlCommand StuIns = new SqlCommand(StuSQL, lee);
            SqlDataReader one = StuIns.ExecuteReader();
            if (one.Read())
            {
                listBox1.Items.Add(one["artist"].ToString() + " - " + one["album"].ToString());
            }
            lee.Close();
我的artist列中有很多行,但是现在我的listbox中只能显示一行artist中的值,请问如何才能把值全部一行一行的显示在listbox中?
谢谢大家了

解决方案 »

  1.   

    用FOR循环读取ONE里的值,判断标准时ONE里有多少行数据
      

  2.   

     if (one.Read()) 
                { 
                    listBox1.Items.Add(one["artist"].ToString() + " - " + one["album"].ToString()); 
                } 
    if (one.read())这句话是是判断第一行是否有记录,不是一个循环,应该把if (one.read())改甩while (one.read())
      

  3.   


    while(one.Read()) 
                { 
                    listBox1.Items.Add(one["artist"].ToString() + " - " + one["album"].ToString()); 
                }