Solved

Sorting datatable problem

Posted on 2009-04-09
6
279 Views
Last Modified: 2013-08-03
Hi,

I create an empty datable then fill data to it.
Then I bind it to datagridview.
The display at datagridview is fine, order by "TrsDate, DOrK).

Then I print the data to excel using datatable.
dtTable.DefaultView.Sort = "TrsDate, DOrK"

For each dtRow as datarow in dtTable.Rows
     Print
Next

The problem is the ouput seq is not as I expected.

What's the problem?

Thank you.
0
Comment
Question by:emi_sastra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24113292
I don't think that actually sorts the data, but just sorts the display of the data (someone correct me if I'm wrong as I'm not a big DataGridView user.  You could sort the data before it hits the DGV (ie. add an ORDER BY clause to the SELECT statement that retrieves the data the DGV is binding to).
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 24113314
Hi,

Please provide sample to do it?

Thank you.
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24113450
Sorry friend, I don't have time to do that.  If you have other specific questions I'll try to help though.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:emi_sastra
ID: 24113495
My question is quite obvious, unless you don't understand since you are not familiar with it.

I have found the answer over the net.

Thank you for your time.
0
 
LVL 1

Accepted Solution

by:
emi_sastra earned 0 total points
ID: 24113511
Just change:

dtTable.DefaultView.Sort = "TrsDate, DOrK"

For each dtRow as datarow in dtTable.Rows
     Print
Next

To :

 Dim dv As New DataView(dtTable)

 dv.Sort = "TrsDate, DOrK"

 For Each dtRow As DataRowView In dv
     Print
 Next

Isn't it obvious and simple solution? Just spend a little time if you are familiar with it.

Thank you.
0
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24113515
Well whoopity doo for you.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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