Creating Dataset, sorting with a dataview and then binding to a combobox
Posted on 2006-07-21
Here's what i need to do. Use an SQl statement to retrieve records from a database. Sort these records by a table in the returned SQL records and then display these records in a combobox. Don't worry about the connection that part is fine.
using VB 2005
Here is what I have:
ds = New DataSet()
'Connect to database and specify sSQL
da = New OleDbDataAdapter("SELECT ALL FROM Table", myConn)
'using DataAdapter enter records from table to DataSet
Catch Ex As System.Exception
MsgBox("Exception: " & Ex.Message & " " & Ex.ToString, MsgBoxStyle.Critical)
dv = New DataView(ds.Tables("MyTable"))
dv.Sort = "MySort"
'bind the dv to the combobox
ComboBox1.DataBindings.Add("Text", dv, "MyColumn")
Catch err As Exception
This works as in it retrieves the correct fields from the database, creates the dataset, sorts the dataview and binds to the combobox. The problem is there are 9 records in the dataset that get sorted and when it binds to the combobox only the very first record shows up in the combobox how do I sort all the records and make all the records appear in the combobox.
On a further note why is VB 2005 so stupid this would have taken 5 seconds in VB6.
Very frustrated VB6 professional trying to learn VB2005