Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Sorting datatable problem

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
emi_sastra
Asked:
emi_sastra
  • 3
  • 3
1 Solution
 
brandonvmooreCommented:
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
 
emi_sastraAuthor Commented:
Hi,

Please provide sample to do it?

Thank you.
0
 
brandonvmooreCommented:
Sorry friend, I don't have time to do that.  If you have other specific questions I'll try to help though.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
emi_sastraAuthor Commented:
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
 
emi_sastraAuthor Commented:
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
 
brandonvmooreCommented:
Well whoopity doo for you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now