Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET Datatable -> how to sort??

Posted on 2014-02-05
7
Medium Priority
?
485 Views
Last Modified: 2014-02-10
Hi guys....

I currently Display what's in my Datatable like this

 Dim DvTheData As New DataView(scorestable)
		
	   For Each dv As DataRowView In DvTheData
    test.Text += dv.row.Item("Score")
Next

Open in new window


Is it possible to sort the results by the column "Time".

The time is sorted by numbers ranging from 0-90
but it also has two letter values which are HT and FT (These are football time)

So i need to be abl to sort it from 0-45 ~ HT~ 46-90 ~ FT ... end result would look like:

1
5
16
35
45
HT
HT
46
49
67
89
FT
0
Comment
Question by:runnerjp2005
[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
  • 4
  • 3
7 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39835933
Yes, with a little work.  Are the numbers stored as numbers (eg. integer) or as strings.  Where do the HT and FT come from IF the others are stored as numbers?

What are the other columns in the underlying table (eg an incrementing primary key) ?
0
 

Author Comment

by:runnerjp2005
ID: 39836016
Hi.... its stored at sting due to having the Numbers AND Letters in it...

Table is setout like so:

scorestable = new datatable
	
	scorestable.Columns.Add("HomeTeam", GetType(String))
	scorestable.Columns.Add("Time", GetType(String))
	scorestable.Columns.Add("Score", GetType(String))
	scorestable.Columns.Add("Lastgoaltime", GetType(String))
	scorestable.Columns.Add("FTtime", GetType(String))

Open in new window


scorestable.Columns.Add("Time", GetType(String)) being the one i would like to order by
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39836522
>>scorestable.Columns.Add("Time", GetType(String)) being the one i would like to order by

OK but is the Lastgoaltime going to give the same sort order and wouldn't require further processing ?
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:runnerjp2005
ID: 39837075
no thats just filled if the score is over 0-0 to let me know when a goal has been scored...

everything will be up in order by Time...

here is the site:http://jarrattperkins.com/football/test.aspx

should show you how it would be orderd
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 39838092
OK, no simple way that I see from that info.

If this is in development and you can implement changes I would suggest adding another column to the underlying table as a primary key which increments.  Then you can sort on that column as it will sort in the order the records were added (chronologically I assume).

If that isn't a possibility then I would suggest creating a second datatable with the same structure.
Now loop through the source datatable and find the earliest record (eg. 1 in your example) and add a copy into the second datatable, now delete that record in the source datatable.  Keep repeating until you have transfered all records into the second datatable with the ordering you desire.
0
 

Author Comment

by:runnerjp2005
ID: 39838191
The datatable is created on page load so it will have a bunch of them loaded together with different times and would be mixed up. I suppose I could create four labors 0-45 lable ht-label and 45-90 lable ending on ft label...with doing that how would I pull all ones between 0-45 and order by number
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 39838239
Convert the string to a number value and then use a simple '<' to test.

(I'm still a little puzzled about things in the background, unless this is randomly generated it must be coming from something such as a database or a file.  I am surprised there isn't somewhere a piece of information one could use to simply sort that data.)
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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