Problem with SQL Update command

Discussion in 'Databases' started by bkagan98, Jun 18, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I am trying to update a record in ms access database.
    If new value (cDesc) contains apostrof (') code crashes.
    Is there another way to do this?

    code:
    string _cSQL = "UPDATE Code SET" +
    " Code.Desc = '" + cDesc.Trim() + "'" +
    " WHERE Code.n_id = " + iCodeID.ToString();
     
  2. Try this:

    Const q As String = Chr(34)
    string _cSQL = "UPDATE Code SET Code.Desc = " + q + cDesc.Trim() + q + " WHERE Code.n_id = " + iCodeID.ToString();

    If you are going to use this method, it's a good idea to define the constant q (for quote) as a global variable at the highest level you can.

    Actually, a better way is to get in the habit of using the command object with parameters in sql insert and update actions.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page