【发布时间】:2013-07-30 19:04:19
【问题描述】:
我有这个函数用来填充我的组合框,但它没有被填充。我也没有收到任何错误。
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);
}
【问题讨论】:
-
您是否验证了阅读器实际上正在返回结果?
-
是的。我做到了。它提供了正确的结果。
标签: c# list combobox using fill