Sorted data is not sorted

A

AMDRIT

I have a table [CoverageLimits] with the following columns

Coverage, Limit, LimitDescription, PerPerson, PerAccident

I load the data from a stored procedure into a datatable

Select Coverage, Limit, LimitDescription, PerPerson, PerAccident From
CoverageLimits Order By Coverage, PerPerson, PerAccident.

I have manually executed this procedure in Query Analyzer and the data comes
out in the desired order.

'A', 'J', '20/40', 20, 40
'A', 'K', '25/50', 25, 50
'A', 'C', '100/300', 100, 300

While the data is actually stored in the heap in this order

'A', 'K', '25/50', 25, 50
'A', 'C', '100/300', 100, 300
'A', 'J', '20/40', 20, 40

When I attempt to populate a combobox with this data from my datatable

dim drs() as datarow

drs = mydatatable.select("Coverage = '" & A & "'")

cbo.DataSource = drs
cbo.DisplayMember = "LimitDescription"
cbo.ValueMember = "Limit"

The data is displayed in its natural ordered state. So then I attempted to
sort the data in the table

dim drs() as datarow
mydatatable.defaultview.sort = "Coverage, PerPerson, PerAccident"
drs = mydatatable.select("Coverage = '" & A & "'")

cbo.DataSource = drs
cbo.DisplayMember = "LimitDescription"
cbo.ValueMember = "Limit"

The data is still displayed in its natural ordered state. Now I can attempt
to sort the array of datarows, but this seems kind of a wasted step, I would
prefer the data be ordered by my stored procedure.

Anyone have any ideas how I can achieve the desired result?

TIA
 
M

Marina

I don't think Select looks at the deafault view's sort. It just works with
the underlying order of the rows.

Use a dataview as your datasource, and put a filter on it.

But, if you say you prefer to have your data be sorted by the stored
procedure, why not do that? If you can have the database do the sorting, you
should.
 
A

AMDRIT

The fix for me was to use the dataview. I do not understand why the data
reverted back to it's native order when I used the Select() method on the
data table. If I want to maintain the order sent by the SQL server, I guess
I will just have to create a temp table and populate it in the order I wish
to see it.




Marina said:
I don't think Select looks at the deafault view's sort. It just works with
the underlying order of the rows.

Use a dataview as your datasource, and put a filter on it.

But, if you say you prefer to have your data be sorted by the stored
procedure, why not do that? If you can have the database do the sorting,
you should.

AMDRIT said:
I have a table [CoverageLimits] with the following columns

Coverage, Limit, LimitDescription, PerPerson, PerAccident

I load the data from a stored procedure into a datatable

Select Coverage, Limit, LimitDescription, PerPerson, PerAccident From
CoverageLimits Order By Coverage, PerPerson, PerAccident.

I have manually executed this procedure in Query Analyzer and the data
comes out in the desired order.

'A', 'J', '20/40', 20, 40
'A', 'K', '25/50', 25, 50
'A', 'C', '100/300', 100, 300

While the data is actually stored in the heap in this order

'A', 'K', '25/50', 25, 50
'A', 'C', '100/300', 100, 300
'A', 'J', '20/40', 20, 40

When I attempt to populate a combobox with this data from my datatable

dim drs() as datarow

drs = mydatatable.select("Coverage = '" & A & "'")

cbo.DataSource = drs
cbo.DisplayMember = "LimitDescription"
cbo.ValueMember = "Limit"

The data is displayed in its natural ordered state. So then I attempted
to sort the data in the table

dim drs() as datarow
mydatatable.defaultview.sort = "Coverage, PerPerson, PerAccident"
drs = mydatatable.select("Coverage = '" & A & "'")

cbo.DataSource = drs
cbo.DisplayMember = "LimitDescription"
cbo.ValueMember = "Limit"

The data is still displayed in its natural ordered state. Now I can
attempt to sort the array of datarows, but this seems kind of a wasted
step, I would prefer the data be ordered by my stored procedure.

Anyone have any ideas how I can achieve the desired result?

TIA
 

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