Solved

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

Posted on 2011-03-11
8
373 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:HainKurt
ID: 35111918
similar thing if you iuse it in sql

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

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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: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 51

Accepted Solution

by:
HainKurt 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

786 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