Solved

Sorting datatable problem

Posted on 2009-04-09
6
258 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

24 Experts available now in Live!

Get 1:1 Help Now