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

C#Microsoft Access

Avatar of undefined
Last Comment
MarkH12518

8/22/2022 - Mon