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 6579371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:53:23+00:00 2026-05-25T15:53:23+00:00

At first I should mention that this problem only occurs in windows forms applications

  • 0

At first I should mention that this problem only occurs in windows forms applications and the same program in web mode for example with MVC3 works perfect.

Some days ago I wrote a very simple windows form program using Visual studio 2010 ultimate with a SQL Express database. I added the database by choosing Add > New item > Service-Based database and an entity data model based on this database in same way. I used Entity framework for adding some new records to tables. I had done such thing with VS 2008 SP1 before with no problem so I did the same. The program compiled and ran with no errors and I entered some new data. after exiting the program I came back to the database and nothing was happened. None of information I had entered had been saved.
I debug the program step by step and everything was alright.
The code below is related to a very simple program with mentioned problem. Database has one table (book):

namespace Book
{
    public partial class BookForm : Form
    {
        BookDatabaseEntities db = new BookDatabaseEntities();

        public BookForm()
        {
            InitializeComponent();
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            Book bookToCreate = new Book();

            bookToCreate.Id = Guid.NewGuid();
            bookToCreate.Title = titleTextBox.Text;

            db.Books.AddObject(bookToCreate);
            db.SaveChanges();
        }
    }
}

I’ll be very grateful if anyone help me. Thanks in advance.

……………..

After editing:

namespace Book
{
    public partial class BookForm : Form
    {
        //BookDatabaseEntities db = new BookDatabaseEntities();

        public BookForm()
        {
            InitializeComponent();
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            var db = new BookDatabaseEntities();
            var bookToCreate = db.Books.CreateObject();

            //Book bookToCreate = new Book();

            bookToCreate.Id = Guid.NewGuid();
            bookToCreate.Title = titleTextBox.Text;

            db.AcceptAllChanges();
            db.Books.AddObject(bookToCreate);
            db.SaveChanges();
        }
    }
}
  • 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-05-25T15:53:23+00:00Added an answer on May 25, 2026 at 3:53 pm

    Finally after lots of searching and asking I found the solution in MSDN forums thanks to Patrice Scribe
    You can see it
    here

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

Sidebar

Related Questions

First check out this code. I seems like it should work for me, but
Example: I have two shared objects (same should apply to .dlls). The first shared
I had a requirement where in the text field the first character should be
[1] In JDBC, why should we first load drivers using Class.forName(some driver name). Why
What should a small team choose for their first game, when they are low
What single aspect of agile development should we implement first to improve our development
First off, I am using Windows XP. I have multiple hard drives and it
This is beyond both making sense and my control. That being said here is
Which should I use? <input type=hidden name=first_name value=<%= person.first_name %> /> or <input type=hidden
First, let's get the security considerations out of the way. I'm using simple authentication

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.