missing operator exception oledb

I am trying to insert into msAccess using ole/c# and am getting a missing operator exception on the first string variable I'm trying to pass.

{"Syntax error (missing operator) in query expression 'Cpty A'."}

The first field is an int, the next 3 fields are doubles. The remaining fields are all strings/varchar. The exception is thrown when I try to pass Cpty A as a value to the insert statement before executing.

Can someone help me on this?

Thanks

try
                {
                    simTmp[i] = expAgg + sExp[i];
                    StringBuilder insertSQL = new StringBuilder(@"INSERT INTO " + tabnm + " (");
                    insertSQL.Append("  [SimNum], ");
                    insertSQL.Append("  [Leg0_MTM], ");
                    insertSQL.Append(" [Leg1_MTM], ");
                    insertSQL.Append("  [SetExp], ");
                    insertSQL.Append(" [CPTY], ");
                    insertSQL.Append(" [KAES_ENTITY], ");
                    insertSQL.Append(" [RPT_LEVEL_1], ");
                    insertSQL.Append(" [RPT_LEVEL_2], ");
                    insertSQL.Append(" [RPT_LEVEL_3]) ");
                    insertSQL.Append(" VALUES (");
                    insertSQL.Append(i + 1).Append(",");
                    insertSQL.Append(leg0exp).Append(",");
                    insertSQL.Append(leg1exp).Append(",");
                    insertSQL.Append(sExp[i]).Append(",");
                    insertSQL.Append(cpty).Append(",");
                    insertSQL.Append(KAESEnt).Append(",");
                    insertSQL.Append(RL1).Append(",");
                    insertSQL.Append(RL2).Append(",");
                    insertSQL.Append(RL3).Append(")");

                    OleDbCommand cmd = new OleDbCommand();
                    OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();

                    cmd.Connection = connect;
                    cmd.CommandType = CommandType.Text;
                   
                    cmd.CommandText = insertSQL.ToString();
                    insSql = insertSQL.ToString();
                    oledbAdapter.InsertCommand = new OleDbCommand(insSql, connect);
                    oledbAdapter.InsertCommand.ExecuteNonQuery();

                    //cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    string exc = e.ToString();
                }
                
            }
            connect.Close();

Open in new window

MarkH12518Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
if you have string values, you need to surround them by quotes:

                   insertSQL.Append(sExp[i]).Append(", '");
                    insertSQL.Append(cpty).Append("',");

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkH12518Author Commented:
Thanks very much for the quick reply. It works.
MarkH12518Author Commented:
Again, thanks for quick response. Works fine now.

Mark
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.