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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

' Causing an Error On a String Field

Status
Not open for further replies.

ctau

IS-IT--Management
Feb 8, 2000
34
US
I am using a string field to allow the user to type in a description of their problem, but if they try to include a single quote in this field they receive an error. Is there anyway to fix this problem without removing the ' from the field?
 
You have to check the field for either ' or " and replace them with /' and /" . They will be inserted into the DB as ' and ".

Use a function similar to this:
Code:
' Replace Quotes Function
Function RQ(string_value)
  string_value = Replace(string_value,"'","/'")
  string_value = Replace(string_value,"""","/""")
  RQ = string_value
End Function


Wushutwist
 
Try this, its a much more efficient solution, and a great way of using ADO.

Code:
set cmInsert as Server.CreateObject("ADODB.Command")
set cmInsert = cnDB 'your connection object
cmInsert.CommandType = 1
cmInsert.CommandText = "INSERT INTO myTable (Name) VALUES (?)"
cmInsert.Parameters.Append cmInsert.CreateParameter("Name",200,1,,myVar)
cmInsert.Execute

This can also be set to be prepared and so will become a temporary stored procedure.

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
i thought you delimit ' with '' and " with ""? adam@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top