Syntax error on 'INSERT INTO' statement when trying to add to access database

Posted on 2004-10-30
Last Modified: 2010-04-23
Sorry if this should be in the DB area, but not sure if the problem is the DB or the VB code.  

The following code does not work (I get a syntax error in INSERT INTO message).  The database QSSupport.mdb is in the correct path with a table called 'tblKey'.  That table has only one field called 'KeyCode2'.  That field is a text field (50 characters), is not indexed, duplicates and zero length strings are allowed.  Can anyone tell me why this is not working?:

Public Sub Update
        Dim conDB2 As New OleDb.OleDbConnection
        Dim cmdKey As New OleDb.OleDbCommand
        Dim myDS As New DataSet

        conDB2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\QSSupport.mdb"

        cmdKey.CommandText = "INSERT INTO tblKey [keycode2] VALUES '7'"
        cmdKey.Connection = conDB2
End Sub
Question by:rbertke
    LVL 16

    Expert Comment


    Change:   conDB2.Open()

           To:   cmdKey.Open()

    LVL 16

    Accepted Solution

    forget that last post, I was wrong.

    Try this:

    "INSERT INTO tblKey [keycode2] VALUES '7'"

    Change to:

    "INSERT INTO tblKey (keycode2) VALUES ('7')"

    I added (  ) in 2 places


    Author Comment

    I had tried variations so much that I thought this had been tried...Obviously not as this worked...Thanks very much!  Rob

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now