locked
Insert String Error RRS feed

  • Question

  • User-883855585 posted

    I am trying to execute a SQL insert statement but I continue to get an error:

    "Unclosed quotation mark after the character string"

    Here is the line where I get the error:

     strQuery = "insert into vim_map	(encid,fin,patname,consulttype,orderdate,completed,compdatetime) " & _
                        "values('" & encid & "','" & fin & "','" & pat & "','" & consult & "','" & orddate & "','" & completed & "','" & compdatetime & "')"""

    I have gone through it several times but cannot find the error.

    Wednesday, November 9, 2016 7:32 PM

Answers

  • User-821857111 posted

    You only need one double quote at the end:

    strQuery = "insert into vim_map	(encid,fin,patname,consulttype,orderdate,completed,compdatetime) " & _
    "values('" & encid & "','" & fin & "','" & pat & "','" & consult & "','" & orddate & "','" & completed & "','" & compdatetime & "')"

    But you should use parameters instead of string concatenation to prevent the possibility of SQL injection (and various syntax errors).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 9, 2016 7:40 PM