Link to home
Start Free TrialLog in
Avatar of MarkH12518
MarkH12518

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MarkH12518
MarkH12518

ASKER

Thanks very much for the quick reply. It works.
Again, thanks for quick response. Works fine now.

Mark