Sorting...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, I have a SQL string that pulls data out of a database - I then
calculate completerates based on Hours and # of Completes. I want to sort
this data (FieldID and CompleteRates) by CompleteRate from Highest to lowest.

I have tried an array, but luck. Does anyone have some pointers or
sugguestins that I can get this done?

Thanks In Advance.
MGR
 
Have you looked at doing it it in your SQL statement and sorting the results
as part of the query?

Alternatively, you could use a generic dictionary and simply sort that,
using your FieldID as the Jey and CompleteRates as the item.

Dictionary<string, string> s = new Dictionary<string, string>();
s.Add("1", "a Item");
s.Add("2", "c Item");
s.Add("3", "b Item");

List<KeyValuePair<string, string>> myList = new List<KeyValuePair<string,
string>>(s);
myList.Sort(
delegate(KeyValuePair<string, string> firstPair, KeyValuePair<string,
string> nextPair){
return firstPair.Value.CompareTo(nextPair.Value);
}
);

foreach (KeyValuePair<string, string> myKey in myList) {
Response.Write(myKey.Key + " " + myKey.Value);
}

Regards


John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 
Back
Top