[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to replace commas in returned value from sql query before binding to control

Posted on 2011-03-11
8
Medium Priority
?
409 Views
Last Modified: 2012-05-11
I have a query from one DB that is used to populate a listbox.  When the values are bound to the listbox for each value that has a , in it I want to replace it with a ;

This because my listbox is a multi select and if I don't remove those commas on the list coming in things are going to get very confused.
Thanks.
0
Comment
Question by:thamilto0410
[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
  • 2
  • 2
8 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35111888
If you need to do the replacement in SQL, we might need to know about the back end.  

If you're doing the replacement in VB.NEt you should just be able to
     Replace(value, ",", ";")
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 35111918
similar thing if you iuse it in sql

select replace('Hain,Kurt',',',';')
--> Hain;Kurt
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 35111941
how do you bind it to listbox? if you have something like this

select id, name from mytable

and bind it to selectbox, use id for value, and name for Text

then when you get it back, you will end up with numbers like '1,3,5,8' instead of text... do not use text columns for values...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:thamilto0410
ID: 35112114
HainKurt and paulmacd,
I have an oracle backend and when I tried using select replace the codebehind objected.

I thought I could make the change in vb.net I am filling a dataset from an oralcedataadapter and binding to the listbox in codebehind DataValueField, DataValueText and Databind.

When I tried the replace on the datavaluefield ie:  

files_processed.DataValueField = replace("thecolumnfromsql", ",", ";")

That also did not work.  What to do next?
0
 
LVL 60

Expert Comment

by:HainKurt
ID: 35112177
you cannot do it in codebehind liek that

either use sql (update your select statement - i prefer this one, easy)
or
in a loop change all item text

for each i as ListItem in dd.Items
  i.Text=i.Text.replace(",",";")
next
0
 
LVL 60

Accepted Solution

by:
HainKurt earned 1000 total points
ID: 35112196
do this after data binding... again, if you have control over sql, use sql solution

select id, name from mytable
-->
select id, replace(name,',',';') as name from mytable
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 35112317
[HainKurt] is right:  your best bet is to do the replace in the SQL.  You can do the replace on the individual list items, but that's slow and messy.
0
 
LVL 1

Author Closing Comment

by:thamilto0410
ID: 35124056
Thank you to hainkurt and paulmacd.  I figured out the way to do it in the sql and it is working great.  All you experts rocks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

650 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