471,066 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Sorting...

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
Apr 13 '07 #1
4 2157
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, strings = 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, stringfirstPair, KeyValuePair<string,
stringnextPair){
return firstPair.Value.CompareTo(nextPair.Value);
}
);

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

Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"MGRideout" <MG*******@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
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

Apr 13 '07 #2
Thanks for the reply John. I am using VB.NET, would this be the same sytax.
Thanks,
MGR

"John Timney (MVP)" wrote:
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, strings = 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, stringfirstPair, KeyValuePair<string,
stringnextPair){
return firstPair.Value.CompareTo(nextPair.Value);
}
);

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

Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"MGRideout" <MG*******@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
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


Apr 13 '07 #3
(ooops . pressed send to early )
6/19/2006

Advanced IComparer // Sorting on Multiple Values

http://sholliday.spaces.live.com/blog/

"MGRideout" <MG*******@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
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

Apr 27 '07 #4

You can look at a IComparer example at:


"MGRideout" <MG*******@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
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

Apr 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by dont bother | last post: by
7 posts views Thread by Federico G. Babelis | last post: by
19 posts views Thread by Owen T. Soroke | last post: by
4 posts views Thread by Ambica Jain | last post: by
7 posts views Thread by Kamal | last post: by
5 posts views Thread by lemlimlee | last post: by
5 posts views Thread by jrod11 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.