Solved

Creating Dataset, sorting with a dataview and then binding to a combobox

Posted on 2006-07-21
4
967 Views
Last Modified: 2008-09-12
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)
        Try
            'using DataAdapter enter records from table to DataSet
            da.Fill(ds, "MyTable")
        Catch Ex As System.Exception
            MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
            Exit Sub
        End Try

         dv = New DataView(ds.Tables("MyTable"))
         dv.Sort = "MySort"
         Try
          'bind the dv to the combobox
          ComboBox1.DataBindings.Add("Text", dv, "MyColumn")
         Catch err As Exception
          MessageBox.Show(Err.Message)
         End Try

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.

Signed,

Very frustrated VB6 professional trying to learn VB2005
0
Comment
Question by:wilsoada
4 Comments
 

Author Comment

by:wilsoada
ID: 17156370
Solved with this:

        dv = New DataView(ds.Tables("MT"))
        dv.Sort = "Sort"
        Try
            'bind the dv to the combobox
            For i As Integer = 0 To dv.Count - 1
                'frmMain.cboType.ComboBox.DataBindings.Add("Items", dv.Item(i), "MN")
                frmMain.cboType.Items.Add(dv.Item(i)("MN"))
            Next i
        Catch err As Exception
            MessageBox.Show(err.Message)
        End Try

Please delete question
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17156481
In order to have a thread deleted, you must post a request in the Community Support.

I have done it for you this time
(http://www.experts-exchange.com/Community_Support/Q_21927743.html)

... but just so you know what to do next time, check it out.

Ta
0
 
LVL 2

Expert Comment

by:JohnWoo
ID: 17160053
wilsoada, instead of making things complicated by using the dataview, why not you just do the sorting in the sql query (SELECT * FROM [Table] ORDER BY [ColumnName] DESC) before binding it to the dataset or datatable. It could have save you a lot of trouble.
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 17160606
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question