?
Solved

Sorting datatable problem

Posted on 2009-04-09
6
Medium Priority
?
292 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
Independent Software Vendors: 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!

 
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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

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’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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