Web App - Double spaces problem

Hi,

     I have a web app with a combo box that fills from a database column.  In the database, some items have two spaces in places, i.e. the one I'm dealing with:

Tape Measure--Power Lock

where -- indicates 2 spaces.  So of course in the webform dropdownlistbox, the two spaces are truncated to one as for all web stuff.  Now when I look in the database from the chosen value in the dropdownlistbox, the two don't match up.  Is there any simple way to do this before I have to write some program to wax all double spaces in the database?

JP
gleznovAsked:
Who is Participating?
 
slyckboyCommented:
Yes a primary key.  Generally a table on a database has a field that acts as a unique identifier.  So you would use that instead of the name field.  For example...
(all my db stuff is oracle, use whatever is appropriate)

Dim strConnect As String = _
      "Data Source=datasource;" & _
      "User ID=" & username & ";" & _
      "Password=" & pwd & ";"

Dim cn As OracleConnection
Dim cmd As OracleCommand
cn = New OracleConnection(strConnect)
cn.Open()

cmd = New OracleCommand("select id,name from your_table",cn))
cbo.datasource = cmd.executereader(commandbehavior.closeconnection)
cbo.DataValueField = "id"     'this line would associate with the id or primary key
cbo.DataTextField = "name"   'this line would associate with the name field or your "Tape Measure--Power Lock" this is what would be displayed in the drop down list

cbo.DataBind()

dim intValue as integer
dim strText as string

intValue = cbo.selecteditem.value  '  This will give you the id (Primary Key) of the selected item in the dropdown list
strText = cbo.selecteditem.text      ' This will give you the name ("Tape Measure--Power Lock") of the selected item in the drop down list

so you would use intValue to compare with the database since it will be the same spaces or not.  If you need me to go further and create a dataset to compare values against let me know.
0
 
ihenryCommented:
Yes, simply replace each space with this " " (without quotes).
0
 
gleznovAuthor Commented:
But that'll take an algorithm on every record right?  Couldn't that cause performance issues?  Or is there a simple command to change " " into " "?

JP
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
toddhdCommented:
Haven't tested it, but I assume that in OnDataBind(), you could simply run something like:
currentitem=Replace(currentitem," ","  ")

0
 
toddhdCommented:
This page shows a snippet of using OnDataBind and a ComboBox
http://www.codeproject.com/cs/miscctrl/ComboView.asp
0
 
slyckboyCommented:
I think it would be less of a strain on resources if you were just to add a pk to the query used to fill the cbobox.

then assign the pk to the datavaluefield of the combobox and the name of the other field to the datatextfield.  Then when you compare to the database compare the datavaluefield to the pk.

If this is not clear let me know and i will elaborate further.
0
 
gleznovAuthor Commented:
pk?  primary key?  I'm not understanding how to do all that?

JP
0
 
toddhdCommented:
slyckboy - I'm not understanding what you are saying either, in regards to the problem that is. The problem was that the spaces between the words Tape Measure and Power Lock are showing up as once space, not two, which HTML is apt to do. (Note that there are NOT two dashes (--) between the words, he only used that as an example to show where the spaces were).

What you showed above seems to be an example of how to load the combobox from a database, but it doesn't seem to address the problem, which is replacing the spaces with two  
0
 
toddhdCommented:
Gleznov, is it reasonable for you to write a very short app that simply reads each description column in the database, does a Replace() as noted above, and then saves the value back to the database? It would take only minutes to write such a thing, and might save you a lot of frustration in the meantime.
0
 
slyckboyCommented:
Maybe i am misunderstanding, but wasn't the reason he was trying to add the two spaces was to compare the selected item with the database.  And since html takes the space out they weren't jiving.  So instead of worrying about the extra spaces and trying to find where every double space is supposed to be and replacing them for every row, every time the page is rendered, it would be less resource intensive to compare something that does not change.  If i am misunderstanding let me know.
0
 
toddhdCommented:
Yup, ok - I see your point now. And you are correct then - going with an index or pk would alleviate the problem.
0
 
gleznovAuthor Commented:
Thanks guys!

JP
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.