如何使用While循环将数据插入列表

时间:2017-08-31 10:00:59

标签: c# mysql ado.net

这是我的代码。我需要将数据插入List form Database

 int gggg = 11;

 MySqlCommand cmd = conn.CreateCommand();
 cmd.CommandType = CommandType.Text;
 cmd.CommandText = "SELECT mobile from student where class = "+gggg;
 MySqlDataReader rdr;
 rdr = cmd.ExecuteReader();
 while (rdr.Read())
 {
     comboBox1.Items.Add(rdr["mobile"]);
     listBox1.Items.Add(rdr["mobile"].ToString());

     values.Add(["mobile"]);
 }

这不起作用。

 values.Add(rdr["mobile"]);

上面的代码通过while循环传递给List(这个代码我用comboBox测试它工作正常)

  comboBox1.Items.Add(rdr["mobile"]);

0 个答案:

没有答案