REPLACE

  • hi

    one of my textfields need apostrophe therefore i use replace function such as replace 1 single quote to 2 single quotes

    then when retrieving the records using pull down menu, i choose the record that used replace function, but it turn out that it cannot find the record name..

    pls giv me some advice ... thanx alot... =)

    p/s: if can, pls giv me full instruction...

  • You only have to replace a single quote with two single quotes when you are inserting a record. When you are comparing the records you only need to compare with one single quote and do not need to use the replace function. Look in your database if you have access and you will see that what was stored in the database(when you used the replace funtion) was one single quote (don't) not (don''t). So basically when you replace ' with '' in your compare you are comparing don't to don''t and that will not match.

    Edward M. Sokolove


    Edward M. Sokolove

  • hi tis is how i retrieve the record from database to the pull down menu:

    Set rsQuery = Server.CreateObject("ADODB.Recordset")

    querySQL = ""

    querySQL = "SELECT DISTINCT Company_Name FROM customer_info ORDER BY Company_Name ASC"

    rsQuery.Open querySQL,Conn

    While NOT rsQuery.EOF

    response.write "<option "

    If CompanyName <> "" Then

    If trim(CompanyName) = trim(rsQuery("Company_Name")) Then

    response.write "SELECTED "

    End If

    End If

    response.write "value='"

    response.write trim(rsQuery("Company_Name"))

    response.write "'>"

    response.write trim(rsQuery("Company_Name"))

    response.write "</option>"

    rsQuery.MoveNext()

    Wend

    rsQuery.close()

    Set rsQuery = Nothing

    pls giv me some advice... thank alot..

    =)

  • I will have to make a few assumptions here and one of those is that you have correctly set up the connection and that you are getting access to the db. I have looked at your code (below) and if I understand it correctly this code is in an ASP page and you are trying to create a pull down box populated with data from a db. If this is true, here is how I would have written the code.

    Set rsQuery = Server.CreateObject("ADODB.Recordset")

    querySQL = ""

    querySQL = "SELECT DISTINCT Company_Name FROM customer_info ORDER BY Company_Name ASC"

    rsQuery.Open querySQL,Conn

    ' No change yet unless the above code doesn't work. In which case you aren't getting connected and wont get any data anyway.

    ' Turn off the scripting mode using the %> tag. This will allow you to enter HTML code just as you would normally

    %>

    <SELECT Name="Company_Name">

    <%Do Until rsQuery.EOF

    If Company_Name =rsQuery("Company_Name") Then%>

    <OPTION Value=<%= rsQuery("Company_Name")%> SELECTED><%=rsQuery("Company_Name")%></OPTION>

    <%ELSE%>

    <OPTION Value=<%= rsQuery("Company_Name")%>><%=rsQuery("Company_Name")%></OPTION>

    <%End If

    rsQuery.Movenext()

    Loop%>

    Another assumption I have made is that Company_Name (which should have been a Dim variable earlier in the code) has been made to equal the Company_Name value through some other method. This is usually done when a form has been submitted using either the POST method or the GET method and then Company_Name = Request.Form("Company_Name") or the Request.QueryString("Company_Name") is used in the code.

    Your end result should, at a minimum, should be a pull down box populated with the names of the companies. If you expected that one of them would have been selected and none showed up then it is probably because the variable Company_Name didn't actually equal what you thought it did. Try using the Response.Write Company_Name & "Test" before entering this code and see what, is printed. If Company_Name doesn't equal anything it will still say Test; otherwise it will say the company name and then the word Test right after it.

    Edward M. Sokolove


    Edward M. Sokolove

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply