We help IT Professionals succeed at work.
Get Started

missing operator exception oledb

MarkH12518
MarkH12518 asked
on
55 Views
Last Modified: 2016-03-23
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

Comment
Watch Question
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE