Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 29th, 2004, 04:18 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Using Apostrophes in text boxes--not supported by SQL

Hello,

Anyone know a way to be able to use apostrophes in text boxes?

I'm using SQL server 2000, ASP and JScript/JavaScript but SQL doesn't support the character ' , it has to be replaced with ' ' for example:

==================
if (typeof Request.Form(txtRequestorName).Item == "string") {
str = Request.Form(txtRequestorName).Item.replace(/\'/g, "''")
} else {
str = ""
}
=================

Thank you,
Barnes

Reply With Quote
  #2  
Old June 29th, 2004, 04:25 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
If you use the appropriate replace statement for the language that you are using, when inserting into the database, it should automatically only insert one single quote, and not two, so that you don't have to worry about two single quotes being stored in your database.

You HAVE TO REPLACE THEM WITH ''. There is no other way. Hopefully this helps.

Reply With Quote
  #3  
Old June 29th, 2004, 04:37 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, I've been reading that, unfortunately, the replace() method is the only way to do this. But it gets tricky, at least for me...thank you for your help.

Has anyone successfully implemented code for the replace() method in JScript?

Reply With Quote
  #4  
Old June 29th, 2004, 04:52 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
function replaceMe(myString)
{
var pattern = /\'/g;
var newString = myString.replace(pattern,"''");
}

By using this function, this should effectively take out all single quotes in your text boxes and replace them with two single quotes so that it will not interfer with your SQL statement.

Keep in mind this is a function and that it returns a value (specifically a string). You can use the function within the sql statement.

Reply With Quote
  #5  
Old June 29th, 2004, 06:20 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hmm,

I must be using the function incorrectly:

-----------------------------------
function replace(txtRequestorName)
{
var pattern = /\'/g;
var newString = txtReqestorName.replace(pattern,"''");
}
---------------------

because I'm getting this error:

-------------------------
Microsoft OLE DB Provider for ODBC Driverserror '80040e14'


[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near 's'. /ProdEvalReq/ER_AddPost.asp, line 91
-------------------------

This tells me that SQL is not catching the apostrophe.

Here is how I have the code:
------------------------
<%
function replace(txtRequestorName)
{
var pattern = /\'/g;
var newString = txtReqestorName.replace(pattern, "''");
}

//create a database connection.
...

//Database.Open ...

...
%>
-----------------------------

Any ideas?

Reply With Quote
  #6  
Old June 30th, 2004, 08:34 AM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Okay, I'll look into why that isn't working for you...I'm not exactly the Javascript person, but I'll try to help you find the answers. Just as a question, why are you using Javascript for ASP? I know that it can be done, but ASP is usually programmed in VBScript, and there is a lot more documentation for VBScript ASP than Javascript. Just a thought.

Reply With Quote
  #7  
Old June 30th, 2004, 09:06 AM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Okay, try this function. Forgot that you have to explicitly tell it to return a value, my bad! Anyway, this should work for you though. Hope that it does!

function replace(txtRequestorName)
{
var pattern = /\'/g;
var newString = txtRequestorName.replace(pattern, "''");
return newString
}

Reply With Quote
  #8  
Old June 30th, 2004, 12:55 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you so much for helping me with this!

You asked in your previous post why we are using JavaScript with ASP...mainly because we haven't adopted the VBScript language here and since the developers knew JavaScript, we decided to go with that.

The function you provided looks like it would work with the return. However, when I plugged it in, I received the same error. But it's probably because I neglected to include that this is a form and that the txtRequestorName is being called from a form. I should probably be using request.form("txtRequestorName").

I think we are very close here. I tried to use the following but received the error again.
-------------------
function replace(txtRequestorName)
{
var pattern = /\'/g;
var newString = request.form(txtRequestorName.replace(pattern, "''"));
return newString
}

------------------

Also, I realized that this function should work for all text boxes not just the txtRequestorName. So in that case, can we just say function replace(String)?:
--------------------------
function replace(String)
{
var pattern = /\'/g;
var newString = String.replace(pattern, "''");
return newString
}
--------------------------

I apologize for not "getting it" but again, this is new to me and I'm the RAD path.

Any additional help you can provide would be most appreciated.

Thank you!!
B~

Reply With Quote
  #9  
Old June 30th, 2004, 01:02 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Okay, you are passing the function a string, it doesn't make a difference what you want to call it in the function.

function replace(blah)
{
var pattern = /\'/g;
var newString = blah.replace(pattern, "''");
return newString
}

As you can see you can name it whatever you want for the function, but you MUST pass it a string:

Response.Write(replace(txtRequestorName))...or what ever you are using. it is a function, it returns a string value, and it has a string for an argument. Pass it the string you want to convert and it will return the converted string.

Reply With Quote
  #10  
Old June 30th, 2004, 01:41 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
But then the error says that blah (or whatever is inthe parenthesis, in my case I named it string) is undefined.
-----------------
Microsoft JScript runtime error '800a1391'


'string' is undefined /ProdEvalReq/ER_AddPost.asp, line 89

Reply With Quote
  #11  
Old June 30th, 2004, 01:51 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
Okay, try replace(Request.Form("txtRequestName")), or however you call a form field using Javascript in ASP. What that is telling you is that something is not being passed.

Reply With Quote
  #12  
Old June 30th, 2004, 02:23 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok, I'll try that.

Thanks again for all your help. I'll let you know once it's solved.

B~

Reply With Quote
  #13  
Old June 30th, 2004, 02:46 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
I'm glad that I can help you (or at least try ). Let me know how it goes...I'm curious about how your going to get it all to work.

Reply With Quote
  #14  
Old June 30th, 2004, 03:45 PM
Barnes Barnes is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 28 Barnes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Funny thing--now I can't get the data to advance in the SQL table to see of the testing of the form works! UGH!!

Reply With Quote
  #15  
Old June 30th, 2004, 04:04 PM
spak111 spak111 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 349 spak111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 25 sec
Reputation Power: 5
Send a message via AIM to spak111
What problem are you running into when trying to move from record to record?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Using Apostrophes in text boxes--not supported by SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump