TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Klemens Engelbrechtsmuller
NA
1
1.5k
DataSet with multiple Tables, mysqldataadapter, update
Jun 26 2014 3:44 AM
Hello, i am using .NET 4.5.1 and a MySQL Database.
I have one Dataset which includes three tables. Two of the tables have a foreign key to the first table.
Now i want to insert a new entry in the first table, and with the generated id (from database - AI) i want also to add new rows in table2 and table3.
But i get this error:
"Cannot add or update a child row: a foreign key constraint fails (`database`.`table2`, CONSTRAINT `FK_XXXX` FOREIGN KEY (`id`) REFERENCES `table1` (`table_id')"
So the first insert works, but the second not. Have anyone an idea? Is it possible that i have to refresh the dataset between the update commands or something like this?
The id from the first insert generated correctly so i can it write to the console.
The commands in the the adapters seems to be correct - if i change a row - the update works fine.
Here is my code for the insert:
MySqlTransaction oSaveTrans;
this.oDbCon.Open();
oSaveTrans = this.oDbCon.BeginTransaction();
this.oDataAdapter1.InsertCommand.Transaction =
this.oDataAdapter1.UpdateCommand.Transaction =
this.oDataAdapter2.InsertCommand.Transaction =
this.oDataAdapter2.UpdateCommand.Transaction =
this.oDataAdapter2.DeleteCommand.Transaction =
this.oDataAdapter3.InsertCommand.Transaction =
this.oDataAdapter3.UpdateCommand.Transaction =
this.oDataAdapter3.DeleteCommand.Transaction =
oSaveTrans;
this.oDataAdapter1.Update(this.oDataSet, "table1");
this.oDataAdapter2.Update(this.oDataSet, "table2");
this.oDataAdapter3.Update(this.oDataSet, "table3");
oSaveTrans.Commit();
this.oDataSet.AcceptChanges();
Thanks, Klemens
Reply
Answers (
0
)
Sql Query for featch data in sql 2008 R2
Excel Password Recovery