Search code examples
c#datasettableadapterdataadapter

C# TableAdapter and DataSet update with multiple table


I'm new in C# and I need some help.

enter image description here

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 ?


Solution

  • 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.

    enter image description here