473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

inserting apostrophes into DB?

When I insert info into a DB from a form, it cuts the string off at the
first apostrophe (").

How would I make it insert the data as-is, with the apostrophes?
Here is the code used to insert the Data:

strsubject = " " & GetFormData("strsubject") & " "
incident = " " & GetFormData("incident") & " "
solution = " " & GetFormData("solution") & " "
InsertQuery="INSERT INTO comments " &_
"(NUserID,thedate, currentdate, commenttype, userid, username,
supplier, person, subject, description, solution, industry, country,
province, city, area, emailsent, clientresponse, compliment,
complaint,telno,subscriber)" &_
" VALUES (" & Session("NUserID") & ", '" &_
thedate & "','" &_
currentdate & "','" &_
strcomment & "'," &_
Session("NUserID") & ",'" &_
alias & "','" &_
Replace(companyname,"'","''") & "','" &_
person & "','" &_
Replace(strsubject, "'", chr(39) & chr(39)) & "','" &_
Replace(incident, "'", chr(39) & chr(39)) & "','" &_
Replace(solution, "'", chr(39) & chr(39)) & "','" &_
industry & "','" &_
country & "','" &_
province & "','" &_
city & "','" &_
area & "','" &_
"no" & "','" &_
"" & "'," &_
compliment & "," &_
complaint & ",'" &_
telno & "','" & ticksubscriber & "');Select @@IDENTITY as id;"

The problem lies with these three:
strsubject, incident, solution

What can I do?

--
Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
Jul 19 '05 #1
4 1925
Server.HTMLEncode() ?

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Lord Merlin" <SP*************@bonzai.org.za_SPAM> wrote in message
news:cc**********@ctb-nnrp2.saix.net...
When I insert info into a DB from a form, it cuts the string off at the
first apostrophe (").

How would I make it insert the data as-is, with the apostrophes?
Here is the code used to insert the Data:

strsubject = " " & GetFormData("strsubject") & " "
incident = " " & GetFormData("incident") & " "
solution = " " & GetFormData("solution") & " "
InsertQuery="INSERT INTO comments " &_
"(NUserID,thedate, currentdate, commenttype, userid, username,
supplier, person, subject, description, solution, industry, country,
province, city, area, emailsent, clientresponse, compliment,
complaint,telno,subscriber)" &_
" VALUES (" & Session("NUserID") & ", '" &_
thedate & "','" &_
currentdate & "','" &_
strcomment & "'," &_
Session("NUserID") & ",'" &_
alias & "','" &_
Replace(companyname,"'","''") & "','" &_
person & "','" &_
Replace(strsubject, "'", chr(39) & chr(39)) & "','" &_
Replace(incident, "'", chr(39) & chr(39)) & "','" &_
Replace(solution, "'", chr(39) & chr(39)) & "','" &_
industry & "','" &_
country & "','" &_
province & "','" &_
city & "','" &_
area & "','" &_
"no" & "','" &_
"" & "'," &_
compliment & "," &_
complaint & ",'" &_
telno & "','" & ticksubscriber & "');Select @@IDENTITY as id;"

The problem lies with these three:
strsubject, incident, solution

What can I do?

--
Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends (John 15:13).

Jul 19 '05 #2
Are you sure it is truncating in the database (not on a form after it is
extracted from the database)?

The Replace statements in your code should take care of the apostrophes in
the insert statement.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Lord Merlin" <SP*************@bonzai.org.za_SPAM> wrote in message
news:cc**********@ctb-nnrp2.saix.net...
When I insert info into a DB from a form, it cuts the string off at the
first apostrophe (").

How would I make it insert the data as-is, with the apostrophes?
Here is the code used to insert the Data:

strsubject = " " & GetFormData("strsubject") & " "
incident = " " & GetFormData("incident") & " "
solution = " " & GetFormData("solution") & " "
InsertQuery="INSERT INTO comments " &_
"(NUserID,thedate, currentdate, commenttype, userid, username,
supplier, person, subject, description, solution, industry, country,
province, city, area, emailsent, clientresponse, compliment,
complaint,telno,subscriber)" &_
" VALUES (" & Session("NUserID") & ", '" &_
thedate & "','" &_
currentdate & "','" &_
strcomment & "'," &_
Session("NUserID") & ",'" &_
alias & "','" &_
Replace(companyname,"'","''") & "','" &_
person & "','" &_
Replace(strsubject, "'", chr(39) & chr(39)) & "','" &_
Replace(incident, "'", chr(39) & chr(39)) & "','" &_
Replace(solution, "'", chr(39) & chr(39)) & "','" &_
industry & "','" &_
country & "','" &_
province & "','" &_
city & "','" &_
area & "','" &_
"no" & "','" &_
"" & "'," &_
compliment & "," &_
complaint & ",'" &_
telno & "','" & ticksubscriber & "');Select @@IDENTITY as id;"

The problem lies with these three:
strsubject, incident, solution

What can I do?

--
Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends (John 15:13).

Jul 19 '05 #3
On Thu, 1 Jul 2004 22:24:18 +0200, "Lord Merlin"
<SP*************@bonzai.org.za_SPAM> wrote:
When I insert info into a DB from a form, it cuts the string off at the
first apostrophe (").

How would I make it insert the data as-is, with the apostrophes?
See this:

Crossposting vs. Multiposting:
http://www.blakjak.demon.co.uk/mul_crss.htm

Then check the respone I posted in another group you posted in.

Jeff

strsubject = " " & GetFormData("strsubject") & " "
incident = " " & GetFormData("incident") & " "
solution = " " & GetFormData("solution") & " "
InsertQuery="INSERT INTO comments " &_
"(NUserID,thedate, currentdate, commenttype, userid, username,
supplier, person, subject, description, solution, industry, country,
province, city, area, emailsent, clientresponse, compliment,
complaint,telno,subscriber)" &_
" VALUES (" & Session("NUserID") & ", '" &_
thedate & "','" &_
currentdate & "','" &_
strcomment & "'," &_
Session("NUserID") & ",'" &_
alias & "','" &_
Replace(companyname,"'","''") & "','" &_
person & "','" &_
Replace(strsubject, "'", chr(39) & chr(39)) & "','" &_
Replace(incident, "'", chr(39) & chr(39)) & "','" &_
Replace(solution, "'", chr(39) & chr(39)) & "','" &_
industry & "','" &_
country & "','" &_
province & "','" &_
city & "','" &_
area & "','" &_
"no" & "','" &_
"" & "'," &_
compliment & "," &_
complaint & ",'" &_
telno & "','" & ticksubscriber & "');Select @@IDENTITY as id;"

The problem lies with these three:
strsubject, incident, solution

What can I do?


Jul 19 '05 #4
Replace ' with '' not two chr(39)s.

Here is how I do it:

Function doubleApost(str)
doubleApost = Replace(str, "'", "''")
End Function
sql = "INSERT tbl(col) VALUES('" & doubleApost(Request.Form("foo")) & "')"

If you are using SQL Server 2000, use SCOPE_IDENTITY, not @@IDENTITY. And
consider using a stored procedure. Your string building will be much
easier, especially if you use a parameters collection. And your chances for
SQL injection attacks will go to nearly nil.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Lord Merlin" <SP*************@bonzai.org.za_SPAM> wrote in message
news:cc**********@ctb-nnrp2.saix.net...
When I insert info into a DB from a form, it cuts the string off at the
first apostrophe (").

How would I make it insert the data as-is, with the apostrophes?
Here is the code used to insert the Data:

strsubject = " " & GetFormData("strsubject") & " "
incident = " " & GetFormData("incident") & " "
solution = " " & GetFormData("solution") & " "
InsertQuery="INSERT INTO comments " &_
"(NUserID,thedate, currentdate, commenttype, userid, username,
supplier, person, subject, description, solution, industry, country,
province, city, area, emailsent, clientresponse, compliment,
complaint,telno,subscriber)" &_
" VALUES (" & Session("NUserID") & ", '" &_
thedate & "','" &_
currentdate & "','" &_
strcomment & "'," &_
Session("NUserID") & ",'" &_
alias & "','" &_
Replace(companyname,"'","''") & "','" &_
person & "','" &_
Replace(strsubject, "'", chr(39) & chr(39)) & "','" &_
Replace(incident, "'", chr(39) & chr(39)) & "','" &_
Replace(solution, "'", chr(39) & chr(39)) & "','" &_
industry & "','" &_
country & "','" &_
province & "','" &_
city & "','" &_
area & "','" &_
"no" & "','" &_
"" & "'," &_
compliment & "," &_
complaint & ",'" &_
telno & "','" & ticksubscriber & "');Select @@IDENTITY as id;"

The problem lies with these three:
strsubject, incident, solution

What can I do?

--
Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends (John 15:13).

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Joe Van Meer | last post by:
Hi all, Been a while since I've done any asp coding, but happy to be getting back into it. My question is what is the best way (now) to handle apostrophes coming in from forms and going into...
1
by: kalbee | last post by:
When we insert text into field in a table, SQL SERVER apparently replaces apostrophes with question marks -- is there a way to not have this occur? We don't have this happen with the mySQL...
3
by: Peter Choe | last post by:
i am trying to add a record of a name. the name has an apostrophe (O'Neil). i am doing this through a servlet and wrote the code to use PreparedStatement. when i do: .... PrepareStatement...
3
by: James Foreman | last post by:
I've got a set of emails in a table, where sometimes they've failed to input the @ properly. Eg james.foreman'abcmail.co.uk How do I write a replace to deal with that? Also, I've got a set...
3
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before...
1
by: mister-Ed | last post by:
I have a datagrid, and when initializing my field variables, I need to double up apostrophes so they are accepted into SQL dbase. In the line below, i'm trying to do this with the Replace function,...
2
by: mister-Ed | last post by:
I have a datagrid, and when initializing my field variables, I need to double up apostrophes so they are accepted into SQL dbase. In the line below, i'm trying to do this with the Replace function,...
4
by: Lucanos | last post by:
Hey Guys, Probably a simple question, but one I am struggling with all the same. I know that in PHP you wrap a text string in apostrophes or quotations - (examples $variable = 'this string' OR...
10
by: Newbie | last post by:
howdy... i am trying to execute a statement where i insert a record with datetime values into a sql database. Dim sqlcmd As New SqlCommand sqlcmd.CommandText = "update tbl_event set...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.