Filling a combo box from a database
-
I am wanting to know what is the best way to fill a combo box from data in a database. Right now I am using an data adapter to fill a dataset that is set as the datasource for the combo box. This seams to work ok. From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? On another combo box I have in my program I use a dataset to read an xml file. Then I use a foreach loop to add the data to the combobox. It is a small list of 10 or so records. The only problem with this is that I haven't found a way to add a value to each item in the combo box. Using the dataset I can set the display member and value member. Just wanted to know what everyone though about this. I am also concerned about how much memory is taken up by the comboboxes and the datasets that fill them. Please let me know what you think about this. I know it is a small thing I want to make sure I'm using the best method. Thanks, JefferyS :)
-
I am wanting to know what is the best way to fill a combo box from data in a database. Right now I am using an data adapter to fill a dataset that is set as the datasource for the combo box. This seams to work ok. From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? On another combo box I have in my program I use a dataset to read an xml file. Then I use a foreach loop to add the data to the combobox. It is a small list of 10 or so records. The only problem with this is that I haven't found a way to add a value to each item in the combo box. Using the dataset I can set the display member and value member. Just wanted to know what everyone though about this. I am also concerned about how much memory is taken up by the comboboxes and the datasets that fill them. Please let me know what you think about this. I know it is a small thing I want to make sure I'm using the best method. Thanks, JefferyS :)
I almost always use a dataset for the for the combo box. I would imagine that most others here would agree that there is nothing wrong with using datasets for combo boxes. Jefferys wrote: From reading about datasets and dataadapter it looks to me that using this method keeps the link to the database open. Is that true? If you are using the Fill method of a dataAdapter to fill your dataset, then you are usually in a disconnected state. The Adapter connects to the database for the query, and then disconnects when it is finished. If you are using a dbConnection object, and opening/closing the connection yourself, then it's possible that you might be leaving the connection open. Either way, it is safer to let the dataAdapter do the work for you.