Reputation: 1000
I'm new in C# and I need some help.
I just want to update row in Session table by code below.
dbDataSet db = new dbDataSet();
SessionTableAdapter sessionTableAdapter = new SessionTableAdapter();
sessionTableAdapter.Fill(db.Session);
var session = db.Session.Where(s => s.idSession.Equals(new Guid("{0F0B0E1A-950E-4BCE-9C68-6D1387EDAC90}"))).SingleOrDefault();
session.endTime = DateTime.Now;
sessionTableAdapter.Update(db.Session);
I got an error at "sessionTableAdapter.Update(db.Session)"
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: The record cannot be deleted or changed because table 'PaidLog' includes related records.
How to fix this error ?
Upvotes: 1
Views: 5204
Reputation: 1000
Solved !
At first that I just only tick Enforce Referential Integrity.
But I try to tick Cascade Update Related Fields and It's works !
I don't know why it work.
Anyone know the reason about this thing?
By the way, thanks to Maheep.
Upvotes: 0
Reputation: 5605
The error message says it all. Session table has foreign key relation with PaidLog. You will have to update child rows from this table first.
See this article on MSDN for more details in the "Updating Two Related Tables in a Dataset with a TableAdapter" section
Or you might want to use TableAdapterManager
Upvotes: 3