Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort a dataset

Status
Not open for further replies.

SBTBILL

Programmer
May 1, 2000
515
US
How do you sort a data set in VB 2003?
 

To my knowledge, you cannot sort the dataset:
The ADO.NET DataSet contains DataTableCollection and their DataRelationCollection . It represents a collection of data retrieved from the Data Source.
You can sort the table in the dataset by using the DataView

Have fun.

---- Andy
 
I'm definitely having fun. How I wish this was VFP where you just send

index on fields tag ordername

and be done with it.
 

So, were you able to sort your 'stuff' in DataView? Or not?

You know, you can order your data in the table in the dataset when you request the data from your DB.....

Have fun.

---- Andy
 
DataTable.DefaultView.Sort = "SomeColumnName".

Consider the following code. The rows are loaded unordered, but I am setting the default view to sort by the column which are output properly to the DataGridView.
Code:
Public Class Form6

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dgv As New DataGridView
        Me.Controls.Add(dgv)

        Dim ds As New DataSet
        ds.Tables.Add("Table1")

        ds.Tables(0).Columns.Add("Col1", System.Type.GetType("System.Int32"))
        ds.Tables(0).Rows.Add(New Object() {24})
        ds.Tables(0).Rows.Add(New Object() {1})
        ds.Tables(0).Rows.Add(New Object() {32})
        ds.Tables(0).Rows.Add(New Object() {-5})

        ds.Tables(0).DefaultView.Sort = "Col1"

        dgv.DataSource = ds.Tables(0)
    End Sub
End Class
 
Thanks RiverGuy that sort line was almost what I was looking for. It works but I'm trying to get a descending list.

I did get a cluge solution added a hidden fields multiplied by -1 that gives me the order I want.
 
Code:
ds.Tables(0).DefaultView.Sort = "Col1 [b][red]DESC[/red][/b]"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top