?
Solved

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

Posted on 2006-07-21
4
Medium Priority
?
980 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

801 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