Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert statement syntax error
Message
 
 
To
22/04/2009 13:53:58
General information
Forum:
ASP.NET
Category:
ADO.NET
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:
01395940
Views:
51
By SP I meant stored procedure. But perhaps you're using Access (looking into your database), if yes, I vaguelly remember seeing similar thread about problem with many fields in one of the VFP forums on tek-tips.

>Yes I believe that I can, i just haven't done it yet because I didn't want to type that much. I like the idea of using the command builder, but I mostly want a solution that works. I'm sorry, but I don't know what you mean by SP
>>
>Jim,
>>
>>Can you specify your InsertCommand directly or use the SP instead? Or do you prefer to use CommandBuilder?
>>
>>What database you're using?
>>
>>>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();
>>>
>>>        }
>>>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform