locked
NullReferenceException was unhandled by user code RRS feed

  • Question

  • I have a LS 2015 silverlight application and I’m having problems copying a record to an archive table.  The code is shown below and I get the error on the last line. The MergedByID is a foreign key (not required) linked to the Users.UserID field. There is a One-to-many relationship between the Users and Media tables. I get the error when the Media.MergedByID is null.  

    MediaArchive arc = this.DataWorkspace.Conn.MediaArchives.AddNew();

                arc.Id = this.Medias.SelectedItem.Id;

                arc.Barcode = this.Medias.SelectedItem.Barcode;

                arc.MergedByID = this.Medias.SelectedItem.User1.UserID;

    Thursday, November 19, 2015 9:56 AM

Answers

  • Hello

    Does your Media Archive table have the same relationships as your Media table? I am also not understanding how you can have a foreign key that is not required, but anyway...if the MediaArchive table is related then I think the last line should be

    arc.MergedByID = this.Medias.SelectedItem.User1;
    Also, how are you getting on with your other issues?


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by jez123456 Thursday, November 19, 2015 10:25 AM
    Thursday, November 19, 2015 10:20 AM

All replies

  • Hello

    Does your Media Archive table have the same relationships as your Media table? I am also not understanding how you can have a foreign key that is not required, but anyway...if the MediaArchive table is related then I think the last line should be

    arc.MergedByID = this.Medias.SelectedItem.User1;
    Also, how are you getting on with your other issues?


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Marked as answer by jez123456 Thursday, November 19, 2015 10:25 AM
    Thursday, November 19, 2015 10:20 AM
  • It's ok thanks. I've sorted this out myself.
    Thursday, November 19, 2015 10:25 AM