Access SQL syntax error when using OleDbCommandBuilder

calendar_today Asked Oct 24, 2013
thumb_up 10 upvotes
history Updated April 14, 2026

Direct Answer

Try this: Immediately after the line var builder = new OleDbCommandBuilder(dbAdapter); add the two lines builder.QuotePrefix = "["; builder.QuoteSuffix = "]"; That will tell the…. This is a prose walkthrough, ranked #42nd of 67 by community upvote score, from 2013.


The Problem (Q-score 3, ranked #42nd of 67 in the Access VBA archive)

The scenario as originally posted in 2013

I am going to INSERT data in Access Database using OleDbDataAdapter in C# but i got an error with message Syntax Error in INSERT INTO Command

BackgroundWorker worker = new BackgroundWorker();
OleDbDataAdapter dbAdapter new OleDbDataAdapter();
OleDbConnection dbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\PMS.mdb");
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.DoWork += InsertJob;
worker.ProgressChanged += InsertJobCompleted;
worker.RunWorkerAsync(args);

And InsertJob Function is:

private void InsertJob(object sender, DoWorkEventArgs e)
{
     var args = (InsertJobArgs)e.Argument;
     try
        {
            dbAdapter.SelectCommand = new OleDbCommand("SELECT * FROM Sheet", dbConnection);                
            dbAdapter.Fill(args.DataTable);
            var builder = new OleDbCommandBuilder(dbAdapter);
            var row = args.DataTable.NewRow();

            row["UserName"] = args.Entry.UserName;
            row["Password"] = args.Entry.Password;
            args.DataTable.Rows.Add(row);

            dbAdapter.InsertCommand = builder.GetInsertCommand();               
            dbAdapter.Update(args.DataTable);
            builder.Dispose();
        }
        catch (Exception ex)
        {
            args.Exception = ex;
            worker.ReportProgress(0, args);
            return;
        }
        worker.ReportProgress(100, args);
}

I recieve Error on line : dbAdapter.Update(args.DataTable);

I tried to debug it with visual studio and found that All the InsertCommand Parameters Values are null

And I tried to insert it manually by this code before call to dbAdapter.Update(args.DataTable);

dbAdapter.InsertCommand.Parameters[0].Value = args.Entry.UserName;
dbAdapter.InsertCommand.Parameters[1].Value = args.Entry.Password;

Why community consensus is tight on this one

Across 67 Access VBA entries in the archive, the accepted answer here holds solid answer (above median) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — solid answer (above median) (+10)

Verbal answer — walkthrough without a code block

Note: the verified answer is a prose walkthrough. If you need a runnable sample, check Access VBA entries ranked in the top 10 of the same archive.

Try this:

Immediately after the line

var builder = new OleDbCommandBuilder(dbAdapter);

add the two lines

builder.QuotePrefix = "[";
builder.QuoteSuffix = "]";

That will tell the OleDbCommandBuilder to wrap table and column names in square brackets, producing an INSERT command like

INSERT INTO [TableName] ...

instead of the default form

INSERT INTO TableName ...

The square brackets are required if any table or column names contain spaces or “funny” characters, or if they happen to be reserved words in Access SQL. (In your case, I suspect that your table has a column named [Password], and PASSWORD is a reserved word in Access SQL.)


When to Use It — classic (2013–2016)

Ranked #42nd in its category — specialized fit

This pattern sits in the 68% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Access VBA archive for a higher-consensus alternative.

What changed between 2013 and 2026

The answer is 13 years old. The Access VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

Is this above-median answer still worth copying?
expand_more

Answer score +10 vs the Access VBA archive median ~4; this entry is solid. The score plus 3 supporting upvotes on the question itself (+3) means the asker and 9 subsequent voters all validated the approach.

The answer has no code block — how do I turn it into a snippet?
expand_more

Use the walkthrough above as a checklist, then open a top-10 Access VBA archive entry for a concrete starting template you can adapt.

Published around 2013 — what’s changed since?
expand_more

Published 2013, which is 13 year(s) before today’s Office 2026 build. The Access VBA object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which Access VBA pattern ranks just above this one at #41?
expand_more

The pattern one rank above is “Row numbers in query result using Microsoft Access”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 3, Answer-score 10, original post 2013, ranked #42nd of 67 in the Access VBA archive. Last regenerated April 14, 2026.