|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
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:
|
Syntax error in INSERT INTO statement
|
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
|
|