Solved

Dataview sort problem

Posted on 2006-07-11
4
653 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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