Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert statement syntax error
Message
From
22/04/2009 13:31:28
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Insert statement syntax error
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Jet/Access Engine
Application:
Desktop
Miscellaneous
Thread ID:
01395927
Message ID:
01395927
Views:
123
Hi All,

Using the code below, I am trying to insert a row of data havine 72 columns into the database. When I reach the line of code that updates the adapter an error is thrown that simply says "Syntax error in INSERT INTO statement.". When I comment out this line the code runs with no errors, but the database is obviously not updated.

I have checked and double-checked all column headings for accuracy and the only thing that I question is that the first column is a PK auto increment field that I do not attempt to update, and the second column is a date field that has a default entry of now() which I also do not update.

Searching the internet only reveals many conversations about whether or not the commandBuilder correctly formats the INSERT statement, but nothing as to the underlying cause or solution to the problem.

Any thoughts would br greatly appreciated.

Thanks,

Jim
         public void InsertData(CData sData)
        {
            OleDbConnection conn = new OleDbConnection(connectionString);
            DataRow row;
            DataSet oDataSet = new DataSet();
            DataTable table = new DataTable(); ;
            try
            {
                conn.Open();
                table.TableName = "tblData";
                OleDbDataAdapter oDataAdapter = new OleDbDataAdapter("select * from tblData", conn);
                OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(oDataAdapter);
                oDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                oDataAdapter.InsertCommand = cmdBuilder.GetInsertCommand();

                oDataAdapter.Fill(oDataSet, "tblData");
                row = oDataSet.Tables["tblData"].NewRow();
               
               #region Columns
               //row["Ave_Nitrate_Level"] = sData.Ave_Nitrate_level;  using this format for all coulmns. sData is an instantiation of a class  containing    fileds and properties for each column in the row.

                oDataSet.Tables["tblData"].Rows.Add(row);
                oDataAdapter.Update(oDataSet, "tblData");

            }
            catch(OleDbException e)
            {
                string errMsg = e.Message;
            }

            if(conn.State == ConnectionState.Open)
                conn.Close();

        }
Next
Reply
Map
View

Click here to load this message in the networking platform