Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   DataAdapter syntax error (http://www.programmingforums.org/showthread.php?t=13845)

kruptof Aug 24th, 2007 4:11 PM

DataAdapter syntax error
 
I having a bit of a trouble using the update method of the DataAdapter no matter what data i put into the dataset whenever i call that method on one of my tables i get an syntax error eventhough i am using the OleDbCommandBuilder, isn't this meant to generate the correct sql statements?

Here is my code;
:

        private void button1_Click(object sender, EventArgs e)
        {
            //connect the to the database
            OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb");
            connection.Open();

            //create the adapters
            OleDbDataAdapter channelAdapter = new OleDbDataAdapter("Select * From channel",connection);
            OleDbDataAdapter threadAdapter = new OleDbDataAdapter("Select * From thread", connection);
            OleDbDataAdapter postAdapter = new OleDbDataAdapter("Select * From post", connection);

            //create the command builders
            OleDbCommandBuilder channelCommandBuilder = new OleDbCommandBuilder(channelAdapter);
            OleDbCommandBuilder threadCommandBuilder = new OleDbCommandBuilder(threadAdapter);
            OleDbCommandBuilder postCommandBuilder = new OleDbCommandBuilder(postAdapter);
            DataSet ds = new DataSet();

            //create the schemas
            channelAdapter.FillSchema(ds, SchemaType.Source);
            ds.Tables["Table"].TableName = "channel";
            threadAdapter.FillSchema(ds, SchemaType.Source);
            ds.Tables["Table"].TableName = "thread";
            postAdapter.FillSchema(ds,SchemaType.Source);
            ds.Tables["Table"].TableName = "post";
           
            //create the relationships
            ds.Relations.Add("ChannelThread", ds.Tables["channel"].Columns["url"], ds.Tables["thread"].Columns["channel"]);
            ds.Relations.Add("ThreadPost", ds.Tables["thread"].Columns["url"], ds.Tables["post"].Columns["thread"]);

            //create the tables
            channelAdapter.Fill(ds,"channel");
            threadAdapter.Fill(ds, "thread");
            postAdapter.Fill(ds, "post");

            //below is just for testing
            DataRow ch = ds.Tables["channel"].NewRow();
            DataRow th = ds.Tables["thread"].NewRow();

            ch["url"] = "http://google.com";
            ch["title"] = "Google";
            ch["type"] = "podcast";
            ch["description"] = "some text here";

            th["url"] = "http://google.com/thread1.htm";
            th["title"] = "google thread 1";
            th["channel"] = "http://google.com";
            ds.Tables["channel"].Rows.Add(ch);
            ds.Tables["thread"].Rows.Add(th);
            channelAdapter.Update(ds, "channel");
            threadAdapter.Update(ds, "thread");
        }


The following error occurs on the last line:
Quote:

Syntax error in INSERT INTO statement

kruptof Aug 24th, 2007 5:30 PM

Through trial and error I discovered the problem was that the database had a field called "size" and after looking that up I realized it was a reserve word, I just changed that and it work.


All times are GMT -5. The time now is 12:33 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC