Solved

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

Posted on 2011-03-11
8
389 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
  • 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 51

Expert Comment

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

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

Expert Comment

by:Huseyin KAHRAMAN
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 51

Expert Comment

by:Huseyin KAHRAMAN
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 51

Accepted Solution

by:
Huseyin KAHRAMAN earned 250 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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