![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 327
Rep Power: 3
![]() |
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:
__________________
Quote:
|
||
|
|
|
|
|
#2 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 327
Rep Power: 3
![]() |
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.
__________________
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Header file internal errors | kruptof | Coder's Corner Lounge | 2 | Jan 14th, 2007 1:12 PM |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 8:44 PM |
| Masm | rsnd | Assembly | 4 | May 20th, 2006 9:05 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 2:12 PM |
| HELP please!!! | hamacacolgante | C | 7 | Nov 21st, 2005 5:36 AM |