Sorting a dataset

J

Jason

Hi All,

I've populated a dataset, but need to return the results,
one by one, in numerical order. I can do this easily when
attaching a datagrid to a dataview, but I can't seem to do
it on just the dataset.

Anyone have any ideas on how to do this?

My code is as follows...

dsDistributionLists.ReadXml(Server.MapPath
("../XMLRoutines/4020DistributionLists.xml"))

Dim holdingTable As New DataTable()
Dim distListID As New DataColumn()
holdingTable.TableName = "holdingTable"
distListID.ColumnName = "distListID"
holdingTable.Columns.Add(distListID)
dsDistributionLists.Tables.Add(holdingTable)

Dim dt As DataTable

For Each dt In dsDistributionLists.Tables
If Val(Mid(dt.TableName, 2)) > 7 Then
Dim newRow As DataRow =
dsDistributionLists.Tables("holdingTable").NewRow
newRow(0) = Val(Mid(dt.TableName, 2))
dsDistributionLists.Tables
("holdingTable").Rows.Add(newRow)
End If
Next

***********************

SORTING THING IN HERE


************************


Dim dr As DataRow
For Each dr In dsDistributionLists.Tables
("holdingTable").Rows
Response.Write(dr.Item(0))
Next
 
M

Miha Markic

Hi Jason,

DataSets/DataTables do not support sorting (if you want sorted data do the
sort in select statament with ORDER BY)
As you've already found out - use DataViews for representing the sorted
data.
Why would you need it on dataset?
 
G

Guest

I thought that, but in the BOL, it says...

"Sorting
Sorting is similar to filtering, in that you specify a
sort expression. A typical sort expression is simply the
name of the column to sort by. For example, to sort by the
OrderDate column, you specify the sort expression
OrderDate. However, you can sort by the value of any
expression, including calculated values. If you call a
table's Select method, you pass the sort expression as a
parameter. If you are using data views, you specify the
sort expression as the value of the view's Sort property.
"

However I can't see any example, that would suit my needs,
in returning the data in numerical order.

Do you have any ideas on how this can be done, or in the
very least, pulling each row from the dataview one by one.

Regards,

J
 
M

Miha Markic

However I can't see any example, that would suit my needs,
in returning the data in numerical order.

Sort by column that contains the numerical value?
Do you have any ideas on how this can be done, or in the
very least, pulling each row from the dataview one by one.

Can you give
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top