Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-07-21
4
Medium Priority
?
989 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Starting up a Project
Suggested Courses

609 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