Solved

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

Posted on 2006-07-21
4
964 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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 …
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now