How to insert a string that contains ' or ,



Hello,

i am using the following statement to insert a message from a user
into the database.

updStmt.executeUpdate("INSERT INTO Contact (uId, replyAddr, subject,
msg) "+
"VALUES (" + userId + "," +
"\'" + replyAddr + "\'," +
"\'" + subject + "\'," +
"\'" + msg + "\')");

The variables userId, replyAddr, subject und msg are of type String.
Now if one of the Strings contain a ' or a , character, the sql
statement gets messed up and causes a SqlException. Is there a way
(How) can i store a string that contains ' or , in the database?
Thanks in advance for your assistance.
.



Relevant Pages

  • Re: Opening Excel from Access
    ... Dim MDBName As String, DefaultDirectory As String, SQLStg As String ... If MsgBox("Do you want to use this database in future?", ... Dim Msg As String ...
    (comp.databases.ms-access)
  • Re: Link the FE to the BE using Code and Path/File
    ... I decided that I would make ONE master database, ... Dim MyAppName As String ... Function AddAppProperty(strName As String, varType As Variant, varValue As ... Dim Msg As String ...
    (comp.databases.ms-access)
  • Re: How to insert a string that contains or ,
    ... The variables userId, replyAddr, subject und msg are of type String. ... Now if one of the Strings contain a ' or a, character, the sql ... can i store a string that contains ' or, in the database? ...
    (comp.lang.java.databases)
  • Re: keyword search
    ... I would have a msg box come up and ask for the ... string to search for. ... I'd also have a button on my form to 'remove filter' or 'show all'. ... > We have a database that keeps track of courses ...
    (microsoft.public.access.forms)
  • Re: Opening Excel from Access
    ... No problem opening Excel whether the database is open or not. ... Dim XLFilePath As String ... Dim Msg As String ...
    (comp.databases.ms-access)