Hi All,
anyone got an example of poulating a combobox from a table stored in SQL server. Still moving over from vb6 and not done this yet.
Cheers in advance
Printable View
Hi All,
anyone got an example of poulating a combobox from a table stored in SQL server. Still moving over from vb6 and not done this yet.
Cheers in advance
There are two ways you can do this.
The first is to open a datatable and bind it to your combo box.
This works fine if you are not modifying the data and you don't need to add anything other than the data you return from the server.
The other is to use a datareader and loop through the records using the datareader.read method and add your values from the reader into the combobox manually.
If you have added data to a combo box in VB6 or previous, it works the same way in .NET. :)
If you populate your combobox an item at a time (like with a datareader or such) then remember to do a combobox1.BeginUpdate() before and a combobox1.EndUpdate() after. Otherwise the control redraws itself after you add each item - and will look funky.
The attached file contains a simple example that retrives data from the Northwind database and populates the combo box.
Many thanks for all your help.