How to populate c# windows forms combobox?

后端 未结 2 1003
醉梦人生
醉梦人生 2020-12-03 04:00

How can I fill a combobox from sql database ( students table with id, and name columns ) , the display text represents the name of a student and the value of the item of com

2条回答
  •  我在风中等你
    2020-12-03 04:05

    First off you need to figure out how you're going to get the data back from the DB, but I'll assume you either know that or intend to ask another question in regards to that. From there, your best bet is to bind some collection to the ComboBox. Here is an example of doing that with a DataSet. You can also bind to List or other IEnumerable, which would make more sense if you're going to use LINQ to get at the data. Here is a question here on SO about binding a List to a ComboBox Perhaps you could tell us how you intend to get at the data so we could give you a more tailored answer?

提交回复
热议问题