Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2007, 05:30 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replace Function Query

Hi,

Using asp.net 1.1 and vb.net I have a form that a user updates and their details are written to a database. One validation check I want to add is to ensure any quotation marks are removed from the entry before this is written to the database.

Within the Submit button sub procedure that updates the data into the database I have used the following coded examples :

1. txtInput.Text.Replace("'", "''")

OR

2. txtInput.Text = txtInput.Text.Replace("'", "''")

However these are not removing the quotation marks. No error is produced but the quotation marks are entered into the database. Any ideas why this is not working. Here's where I'm using the code :

Code:
Sub btnSubmit_Click(sender As Object, e As EventArgs)

    'txtInput.Text.Replace("'", "''") - 1st attempt
    txtInput.Text = txtInput.Text.Replace("'", "''") - 2nd attempt

   'Calls function to update database 
   UpdateDB(txtInput.Text)

    'Confirmation message
    Response.Write("Details submitted - thanks")

End Sub


 
Old August 3rd, 2007, 11:38 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try this:
txtInput.Text = txtInput.Text.Replace("'", "#39;")

What I imagine is happening is that since you are escaping the apostorphe ('') so it can be inserted into SQL that you are only seeing the one apostorphe in your table. The ascii code above will generate an apostorphe when the page is rendered by the browser.

hth



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old August 4th, 2007, 04:59 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks

However this is still not working. Whenever an entry is inputted with quotation marks e.g. "myentry" the database records the value with the quotation marks i.e. "myentry". Basically I want it to remove the quotation marks leaving just myentry.

Any ideas ? Here's the code I've used to date which does seem to look ok ? Also I'm using an access database.

Code:
Sub btnSubmit_Click(sender As Object, e As EventArgs)

       'txtInput.Text.Replace("'", "''")
       'txtInput.Text = txtInput.Text.Replace("'", "''")
        'txtInput.Text = txtInput.Text.Replace("'", "")

                  txtInput.Text = txtInput.Text.Replace("'", "")

        UpdateDB(txtInput.Text)

        Response.Write("Details submitted - thanks")

    End Sub

 
Old August 4th, 2007, 05:07 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Change the code to:

Sub btnSubmit_Click(sender As Object, e As EventArgs)
                  txtInput.Text = txtInput.Text.Replace("\"", "")

        UpdateDB(txtInput.Text)

        Response.Write("Details submitted - thanks")

    End Sub
 
Old August 4th, 2007, 05:29 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks

In the end the following line of code worked :

txtPassword.Text = txtPassword.Text.Replace("""","")

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Extending the Replace Function designdawg Access 9 February 19th, 2008 12:39 PM
replace function keyvanjan Classic ASP Basics 3 May 15th, 2006 12:57 AM
Character replace function? echovue Access 2 December 21st, 2004 01:53 PM
replace function Adam H-W Classic ASP Basics 3 September 20th, 2004 09:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.