0

Edit

There is one thing that I hadn't considered; there are some Relationships specified on these tables. Document is on the many side of a one-to-many with Folder, however it is also on the one-side of a one-to-many relationship with another table called OCR. Do these relationships need to captured in my Table or Column attributes? any help is greatly appreciated.

Another dreaded "Row not found or changed" exception.

We're trying to update an existing entry in a table by change one column's value. The tables we have are specified in code section (1). I'm getting to an instance of the Document Table through the code specified in code section (2) but that's where I hit an exception.

Here are the things I have tried to resolve the issue:

i. tried marking every Column (in both Document and Folder) as UpdateCheck=UpdateCheck.Never, As well as tweaking with CanBeNull

ii. tried to resolve changes after SubmitChanges call in part two using both ChangeConflict.Resolve(RefreshMode.KeepChanges) and DataContext.Refresh(conflict, RefreshMode.KeepChanges) on the myContext.ChangeConflicts set, and then do a re-SubmitChanges

iii. tried disabling the EntityRef<Folder> in Document

iv. tried re-adding the Document table entry -- this failed because the entry does indeed exist

v. gently rocking back and forth, screaming myself hoarse (this actually helped a bit)

Thanks!

(1)

    [Table(Name = "Document")]
    public class Document
    {
        [Column(Name="Folder_ID", IsPrimaryKey = true)]
        public int Folder_ID;

        private EntityRef<Folder> folder;
        [Association(Storage = "folder", ThisKey = "Folder_ID", OtherKey = "Folder_ID")]

        public Folder Folder
        {
            get { return folder.Entity; }
            set { folder.Entity = value; }
        }
        [Column]
        public int Document_ID;

        [Column(IsPrimaryKey = true)]
        public int Image_ID;

        [Column]
        public string ImageName;

        [Column]
        public string ReasonForRejection;
    }

    [Table(Name = "Folder")]
    public class Folder
    {
        [Column(Name = "Folder_ID", IsPrimaryKey = true)]
        public int Folder_ID;

        [Column(Name = "FolderName")]
        public string FolderName;
    }

(2)

 public void MarkRejectReasonForImageID(int id, string rejReason, string dbPath) 
 {
    // Create DataContext for MS Access '97 DB
    DataContext myContext = new DataContext(new OleDBConnection(CreateJET4_OleDBConnectionString(dbPath));

    // Add load options so that Folder entity is attached 
    DataLoadOptions loadOptions = new DataLoadOptions();
    loadOptions.LoadWith<Document>(d => d.Folder);
    myContext.LoadOptions = loadOptions;
    // Make sure ObjectTracking is turned on
    myContext.ObjectTrackingEnabled = true;
    myContext.Connection.Open();
    // Get Document from context matching input id
    Document doc = myContext.GetTable<Document>().Where(d => d.Image_ID == id).ToList().FirstOrDefault();

    if(doc!=null) {
      // Mark matching reject reason on document
      doc.ReasonForRejection = rejReason;

      // Resubmit table changes
      myContext.SubmitChanges(); // <-- "Runtime Exception: Row not found or changed."

    }
    myContext.Connection.Close();
}
Ian Ray
  • 378
  • 2
  • 18
  • Perhaps you can try double checking the types as explained here http://stackoverflow.com/a/83999/430661 Edit: never mind, missed the fact that you tried that already – Alex Paven May 03 '17 at 16:26
  • Normally I'd suggest some form of tracing to see the exact queries that are issued and deduce from there what the problems can be, but I realize Access doesn't really have a lot of facilities for this... perhaps you can still try something like https://msdn.microsoft.com/en-us/library/aa188211.aspx#odc_4009c15_topic4 and get some more information though. – Alex Paven May 03 '17 at 16:31

0 Answers0