Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:15:07+00:00 2026-06-01T08:15:07+00:00

Hi I have a problem saving 2 tables of my database at the same

  • 0

Hi I have a problem saving 2 tables of my database at the same time but my first table saves without a problem alone. The second table is related to the first table and has FK already. Please help..here is my code. Thanks

        //Save to Database
        //1st Table
        casecrawlerdbEntities1 db = new casecrawlerdbEntities1();
        document document = new document();
        document.DocumentNo = DocumentNo;
        document.Description = Description;
        document.Author = Author;
        document.PublishedDate = DateTime.Parse(PublishedDate); ;
        document.Summary = Summary;
        document.SearchKeys = richTextBox9.ToString();
        document.References = url;
        document.IsPublic = false;
        document.IsPublished = false;
        document.CreatedDate = DateTime.Now;
        db.documents.AddObject(document);
        db.SaveChanges();

        //2nd Table
        content content = new content();
        content.ContentType = ContentType;
        content.Content = Content;
        db.contents.AddObject(content);
        db.SaveChanges();

        MessageBox.Show("Saved to Database");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:15:08+00:00Added an answer on June 1, 2026 at 8:15 am

    Before calling db.contents.AddObject(content);, do:

    content.Document = document; 
    

    (assuming that this is how the relation to the Document is named).

    Also, you may try calling db.SaveChanges(); only once (after the contents is created).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CakePHP framework with MySQL database and I have problem in saving
Very weird problem. Saving email addresses to my database, but when I query those
I have problem with saving object to database with NHibernate. Program throws no error
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
We have a problem with the Euro character when saving and retrieving it from
I have a table in a MySQL database. The name of the table is
My problem is: I have a table with an auto_increment column. When I insert
We have an MS Access 2007 database with a simple form displaying table data.
I have here java code accessing mySQL database. It checks if table exists. The
I have a movie database (postgreSQL). One of tables contains actors and movie titles.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.