Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2007, 04:02 PM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default OleDbDataAdapter Help

Problem: Trying to update a single table in my database and when using the dataAdapter Update method it is throwing exception "Syntax error in INSERT INTO statement."

Here is my call:
Code:
DataTable changes = ds.Tables["orders"].GetChanges();
db.updateOrders(ref changes);
Code:
Code:
public void updateOrders(ref DataTable changes)
        {
            string selectSQL = "SELECT * FROM orders";
            try
            {
                conn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.SelectCommand = new OleDbCommand(selectSQL, conn);

                OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
                cb.SetAllValues = false;

                da.UpdateCommand = cb.GetUpdateCommand();
                da.DeleteCommand = cb.GetDeleteCommand();
                da.InsertCommand = cb.GetInsertCommand();

                da.Update(changes);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }


The following has already been executed:
Code:
private DataTable createOrders()
        {
            DataTable dt = new DataTable("orders");

            DataColumn[] pk = new DataColumn[1];
            pk[0] = new DataColumn("idOrder", typeof(int));
            dt.Columns.Add(pk[0]);
            dt.PrimaryKey = pk;

            dt.Columns.Add(new DataColumn("fkVendor", typeof(int)));
            dt.Columns.Add(new DataColumn("fkDept", typeof(string)));
            dt.Columns.Add(new DataColumn("date", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("recDate", typeof(DateTime)));
            dt.Columns.Add(new DataColumn("requester", typeof(string)));
            dt.Columns.Add(new DataColumn("accountCode", typeof(string)));
            dt.Columns.Add(new DataColumn("fkBlanketPO", typeof(string)));
            dt.Columns.Add(new DataColumn("notes", typeof(string)));

            string sql = "SELECT * FROM orders ORDER BY orders.idOrder DESC";
            execute(sql, ref dt, true);
            return dt;
        }

The table is populated correctly and the new row is marked as "Added" state but I am not sure on why I am receiving SQL errors. I am accessing an Access database and I am not sure how the dataadapter fills in the appropriate parameters. Does it include quotes, how does it handle dates, etc...

The following is the command generated by the OleDbCommandBuilder :

INSERT INTO orders (idOrder, fkVendor, fkDept, date, recDate, requester, accountCode, fkBlanketPO, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)

Hopefully i didnt leave out any required information.

Thanks ahead of time
 
Old July 5th, 2007, 02:11 PM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Error fixed...

Was to due with generated insert statement doesnt take into consideration date is a reserved word in access... dumb mistake by myself
[date]






Similar Threads
Thread Thread Starter Forum Replies Last Post
OleDbDataAdapter Problem RAnderson14 Pro VB Databases 0 April 11th, 2008 10:29 AM
database paging using asp table+ oledbdataadapter yamensaleh ASP.NET 2.0 Basics 0 January 27th, 2007 10:09 AM
OleDbDataAdapter myNameIsRon ADO.NET 2 June 9th, 2005 04:16 PM
DataSet and OleDbDataAdapter ? justin_min ADO.NET 2 November 22nd, 2004 10:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.