Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Below data coming from database in one line.I need to get this data in a dropdownlist.one after the other .like this,

US Mail (9.50)
First Class Mail (Canada) (15.00)
Airmail (International Addresses) (26.00)
Next Day Air (16.00 + 28.66 = 44.66) etc..



US Mail (9.50) First Class Mail (Canada) (15.00) Airmail (International Addresses) (26.00) Next Day Air (16.00 + 28.66 = 44.66) UPS 2ND Day (11.00 + 17.44 = 28.44) UPS Ground (10 + 9.29 = 19.29) UPS NEXT DAY AIR (10.00 + 17.44 = 27.44)



Please help me with the query.
Thanks
Posted

1 solution

If you are extracting that as one line, in the format shown at the bottom of your question, then you can't do it automatically - there is nothing distinct which marks the "end" of one option and teh beginning of another. It easy if you use a special character such as '|':
US Mail (9.50)|First Class Mail (Canada) (15.00)|Airmail (International Addresses) (26.00)|Next Day Air (16.00 + 28.66 = 44.66)|UPS 2ND Day (11.00 + 17.44 = 28.44)|UPS Ground (10 + 9.29 = 19.29)|UPS NEXT DAY AIR (10.00 + 17.44 = 27.44)
because then you can split the string easily, either in SQL or in your C# / VB code. But without that...there isn't a lot to go on.
 
Share this answer
 
Comments
SoMad 12-Feb-14 6:31am    
It does look like each entry ends with an amount followed by a closing parenthesis. But that's a thin rule. It's real thin.

Soren Madsen
OriginalGriff 12-Feb-14 6:48am    
Yeah - I noticed that. But you can't just use the closing parenthesis, SQL doesn't support regexes, and what happens if a local currency symbol gets in there?

I'd much rather be safe and use a defined separator...or better a separate table with a DispatchVia code and a price.
SoMad 12-Feb-14 6:51am    
I agree. Assuming the OP is able to change the formatting of the items in the database or add tables. It's not really clear from the question.

Soren Madsen
Challa92 12-Feb-14 7:00am    
So how do i write a query in code behind(in C# ) using execute scalar? I tried the query u modified..still does'nt work!
OriginalGriff 12-Feb-14 7:18am    
I didn't give you a query...it was a suggestion as to how to improve the data so as to make it possible to split it reliably.

If you have read the data from SQL into a string in C#, and you have '|' separating them, then it's trivial:
string[] separateLines = lineFromSql.Split('|');

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900