我有这个功能,我用它来填充我的组合框,但它没有被填充。我也没有收到任何错误。
public List<string> showStudents()
{
List<string> list = new List<string>();
string rollno;
command = connection.CreateCommand(); //command and connection have been initialized earlier..
command.CommandText = "select RollNo from student";
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
rollno = reader["RollNo"].ToString();
list.Add(rollno);
}
reader.Close();
return list;
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}
}
}
}
comboBox.DataSource=showStudents();
可能是什么问题?请帮忙!!谢谢你..
已经得到答案.. :)
foreach(string str in showStudent())
{
comboBox.Items.Add(str);
}