Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert a value with single quote?

Status
Not open for further replies.

chinedu

Technical User
Mar 7, 2002
241
US
What is the best way to make use of single quotes like it's, don't, can't etc?
If I type in the word "it's" as a value for a field, it returns an error that says "syntax error near s.
Once I remove the single quote, it works but we need the single quotes.
What do I include to the field ItemDesc in the insert statement below for the client to be able to type in words like can't, don't it's etc without getting an error?
Thanks in advance




'insert the Item Descriptions, from grid
For x = 0 To intCount
If request.form(&quot;txtItemDesc&quot;&x) <> &quot;&quot; then
strItemDesc = request.form(&quot;txtItemDesc&quot;&x)
else
strItemDesc = &quot;N/A&quot;
end if

strSQL = &quot;INSERT INTO cart( &quot;
strSQL = strSQL & &quot;ItemDesc) &quot;
strSQL = strSQL & &quot;VALUES( &quot;
strSQL = strSQL & &quot;'&quot;&strItemDesc&&quot;')&quot;
'response.write(strSQL)
'response.end
response.write(&quot;<br>&quot;)
objConn.execute(strSQL)

Next
 
Try this:
Code:
strSQL = strSQL & Chr(34) & strItemDesc & Chr(34) & &quot;)&quot;

Hope This Help
PH.
 
hi!
I tried inserting the following values:

Canon's petite, easy-to-transport i70 Color Bubble Jet Printer makes a big impression with its photo prints

and received the following error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The name 'Canon's petite, easy-to-transport i70 Color Bubble Jet Printer makes a big impression with its photo prints' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

 
just after the if statement but before insert statement,
strItemDesc = Replace(strItemDesc,&quot;'&quot;,&quot;''&quot;)
That took care of it but then I have another challenge which is retrieving the data I just inserted.
When I try to retrieve it, I only get Canon, nothing else.
Remember I inserted this:
Canon's petite, easy-to-transport i70 Color Bubble Jet Printer makes a big impression with its photo prints

Below is the code I am using to retrieve it but it is only retrieving only the word Canon.
Can someone please tell me how to make the code retrieve the rest of the text?
Thanks.
Response.Write(&quot;<INPUT TYPE='TEXT' SIZE='80' NAME='txtItemDesc' VALUE='&quot; & rsPersonData(&quot;ItemDesc&quot;) & &quot;' >&quot;)
 
Try this:
Code:
Response.Write(&quot;<INPUT TYPE='TEXT' SIZE='80' NAME='txtItemDesc' VALUE=&quot; & Chr(34) & rsPersonData(&quot;ItemDesc&quot;) & Chr(34) & &quot; >&quot;)

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top