Solved

Dataview sort problem

Posted on 2006-07-11
4
650 Views
Last Modified: 2011-04-14
I put the results of a running a stored procedure into a dataset. I then created a dataview to be able to sort:

dim dv as new dataview
with dv
   .table = objDataSet.tables("spResults")
   .sort = "ChargeNumber desc"
end With

I load the table into my datagrid. Works fine. sorted and everything. The problem is, I'm trying to load the results into an excel spreadsheet from the dataview but it won't sort.

for dtRow = 0 to dv.count - 1
   osheet.cells(3, 1).value = dv.table.rows(dtrow).item("Charge")
   .....
and so on

My guess is when I use
   dv.table.rows(dtrow).item("Charge")
it is looking at the first record of the dataview before it was sorted.
How can I change this? I need to go by the sorted order.

Thanks
0
Comment
Question by:MadIce
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 350 total points
ID: 17086338
Yes, you are getting the data from the table, which is not sorted, rather than from the dataview, which is sorted.  Try this instead

        For Each drv As DataRowView In dv
            osheet.cells(3, 1).value = drv("Charge")
            'and so on
        Next

Roger
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17086450
Roger, how many people get that wrong about the DataView.Table property?  It is not very intuitive, now is it?

Bob
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17086597
No, it's not very intuitive.

I reckon a large part of the problem is DataRow cf DataRowView.  "Data is in DataRows which are in DataTables: DataRowViews are different, and therefore a bit frightening.  I'd better get back to the table."  But the only real difference is that a DataRow can have data in different .RowStates whereas a DataRowView is restricted to one.  And although it is possible to look at (in a DataTable) or choose (for a DataView) other .RowStates than Current, I wonder how many people ever do that for real.

Sermon over.  It's my bedtime ;-)

Roger
0
 

Author Comment

by:MadIce
ID: 17091620
Thanks. Reading your other commit, I was trying to pull from the table rather than the DataRowView. Guess I better read up on DataViews again. Thanks again....
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now