Solved

Help with sorting column is DataTable using vb.net

Posted on 2014-02-23
6
2,262 Views
Last Modified: 2014-02-24
Hi,

I'm using the code below to search data in a DataTable, How do I sort the results by SN?

Dim SearchCriteria As String = "Substring(SN, 1,3) IN (" & xyz & " )"

                Dim FilteredDTA As DataTable
                Dim DVA As New DataView(dtsetLinkAOP6A.Tables(0), SearchCriteria, Nothing, DataViewRowState.CurrentRows)
                FilteredDTA = DVA.ToTable
                If FilteredDTA.Rows.Count > 0 Then

                    C1Screen1.Columns(0).Visible = True
                    Me.C1Screen1.DataSource = FilteredDTA.DefaultView.ToTable(True, New String() {"SN", "AGD", "CA"})
                    Me.C1Screen1.Columns("SN").Width = 60
                    Me.C1Screen1.Columns("AGD").Width = 500
                    Me.C1Screen1.Columns("CA").Width = 350
                Else
                    MsgBox("No Records Found")

                End If

Thanks,

Victor
0
Comment
Question by:vcharles
6 Comments
 
LVL 40
ID: 39881766
I di not test, but I would try sorting the DataView before using it to create a table.

DVA.Sort = "SN"
0
 

Author Comment

by:vcharles
ID: 39882456
Hi,

Unfortunately it does not work.

Thanks,

Victor
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39882805
Looking at the documentation for the Sort property, I suspect you need to add either "ASC" or "DESC" in addition to the column name.

e.g.

DVA.Sort = "SN ASC"

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39882813
Could it be problem related to you trying to sort numeric values in a string column?
0
 

Author Closing Comment

by:vcharles
ID: 39882823
Thank You.
0
 

Author Comment

by:vcharles
ID: 39882832
It worked with DVA.Sort = "SN ASC".

Thanks,

V.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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