Solved

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

Posted on 2006-07-21
4
966 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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