INSERT statement Syntax in VB.net with Access DB

Posted on 2008-02-09
Medium Priority
Last Modified: 2010-04-21
I have an INSERT statement that appears identical to every other INSERT statement I have used but for some reason I keep getting an error message about the syntax. I've no idea what I am doing wrong. Any suggestions as to what's wrong with the code I have pasted below? Is there something huge wrong with the INSERT that I'm missing? It's a VB.net application that reads and writes to an Access XP database. All the field names and table names are correct as far as I can make out. The detail of the error message is as follows: "In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user". Any thoughts?
Dim myOLEDBConnection As New OleDbConnection(My.Settings.WillsDBConnectionString)
        Dim myWillsCommand As New OleDbCommand("INSERT INTO tblWills (WillLetter, WillNumber, WillCode, ClientName, Address, DocNo, DiskNo, Comments, Year, Createdby, Checkedby, Location) VALUES (@WillLetter, @WillNumber, @WillCode, @ClientName, @Address, @DocNo, @DiskNo, @Comments, @Year, @Createdby, @Checkedby, @Location)", myOLEDBConnection)
        With myWillsCommand.Parameters
            .Add(New OleDbParameter("@WillLetter", Me.txtWillLetter.Text))
            .Add(New OleDbParameter("@WillNumber", Me.txtWillNumber.Text))
            .Add(New OleDbParameter("@WillCode", Me.txtWillNo.Text))
            .Add(New OleDbParameter("@ClientName", Me.txtTestatorName.Text))
            .Add(New OleDbParameter("@Address", Me.txtTestatorAddress.Text))
            .Add(New OleDbParameter("@DocNo", Me.txtWillDocNo.Text))
            .Add(New OleDbParameter("@DiskNo", Me.txtWillDiskNo.Text))
            .Add(New OleDbParameter("@Comments", Me.txtWillComment.Text))
            .Add(New OleDbParameter("@Year", Me.txtWillYear.Text))
            .Add(New OleDbParameter("@CreatedBy", Me.txtWillCreator.Text))
            .Add(New OleDbParameter("@CheckedBy", Me.txtWillChecker.Text))
            .Add(New OleDbParameter("@Location", Me.txtWillLocation.Text))
        End With
        MsgBox("New Entry added to Wills Database for" & Me.txtTestatorName.Text)

Open in new window

Question by:BozM
LVL 29

Accepted Solution

Göran Andersson earned 2000 total points
ID: 20857021
Year is a reserved keyword.

Change the name of the field in the table, or if that is not possible, put square brackets around the name in the query: [Year].

Author Closing Comment

ID: 31429449
Spot on and first time round! Thank you so much. I was doing a lot of head scratching on that one! I can't believe it was so straight forward!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

600 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