Solved

Help with sorting column is DataTable using vb.net

Posted on 2014-02-23
6
2,053 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 74

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

16 Experts available now in Live!

Get 1:1 Help Now