Solved

Web App - Double spaces problem

Posted on 2004-11-02
221 Views
Last Modified: 2010-04-23
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
0
Question by:gleznov
    12 Comments
     
    LVL 20

    Expert Comment

    by:ihenry
    Yes, simply replace each space with this " " (without quotes).
    0
     

    Author Comment

    by:gleznov
    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
     
    LVL 8

    Expert Comment

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

    0
     
    LVL 8

    Expert Comment

    by:toddhd
    This page shows a snippet of using OnDataBind and a ComboBox
    http://www.codeproject.com/cs/miscctrl/ComboView.asp
    0
     
    LVL 6

    Expert Comment

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

    Author Comment

    by:gleznov
    pk?  primary key?  I'm not understanding how to do all that?

    JP
    0
     
    LVL 6

    Accepted Solution

    by:
    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
     
    LVL 8

    Expert Comment

    by:toddhd
    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
     
    LVL 8

    Assisted Solution

    by:toddhd
    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
     
    LVL 6

    Expert Comment

    by:slyckboy
    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
     
    LVL 8

    Expert Comment

    by:toddhd
    Yup, ok - I see your point now. And you are correct then - going with an index or pk would alleviate the problem.
    0
     

    Author Comment

    by:gleznov
    Thanks guys!

    JP
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now