Re: sorting data in a row
I don't quite understand your question but if you want to sort the data coming from a database on certain field(s), why don't you just use "order by" in your query?
Re: sorting data in a row
I agree. It seems only logical to put it into your SQL command, then you don't need to reorder the output.
Re: sorting data in a row
I don't know the SQL to sort the rows' data at runtime. Do you know the SQL?
Thanks,
Victor
Re: sorting data in a row
I don't think ORDER BY will work in this case. How about editing that first post and enclosing the code in CODE tags. That will make it much easier to read.
Also, unless you are using a version of .NET prior to 2005, you should get rid of the ArrayList in favor of List (of T), which is a strongly typed list, and much superior.
It appears that you are taking a string, which is a comma separated list of countries, splitting the string on the comma, sorting the resulting array, then re-packing them into a string. All that looks fine (though an odd way to set up a database...not that I haven't done the same once before).
As for the main question:You need to add just one line to your code. Right after the call to split, you need to add this line:
sortedList = ""
Otherwise, sortedList still holds the original list, and you just concatenate the new stuff onto it.
Re: sorting data in a row
I still can't see why you can't 'ORDER BY country ASC'? Or whatever it actually is, my SQL is rusty, haven't touched it for a couple of years.
Re: sorting data in a row
Unless I'm missing something you only need to amend your query to
Code:
SELECT ID, country FROM Identification_data ORDER BY country ASC
or
Code:
SELECT ID, country FROM Identification_data ORDER BY country DESC
if you want it in reverse alphabetical order.
Re: sorting data in a row
Since the Country field is being split, then re-ordered, I understand the Country field not to hold a single country, but to hold something like this:
"USA,GER,FRA"
and he wants to end up with:
"FRA,GER,USA"
ORDER BY won't do that, because it will only order a collection of records, not a bunch of pieces within a string.
Re: sorting data in a row
Yeah Shaggy, makes perfect sense if "BEL,CAN,DEU,USA" is the value of dr("COUNTRY").ToString for one record. It would have paid for me to have read the original post, but that code without syntax highlighting and indentation...hurts my eyes...and swells my brain! ;-)
Re: sorting data in a row
It still comes down to adding only one line to fix the problem.