WinForms – Database Changes not sticking.

Saturday afternoon I spent trying to get a Windows Forms application to add data to a database.  It all seemed to work correctly.  Add changes, no errors.  Close window, open window.  Yep changes are there.  Close application, re-run application.  Yep, changes still there.  Make a change to the code, re-run.  No data.

This happened with either an SQL database that was in my project or an Access database that was in my project.

Further if I checked the database via Visual Studio, it looked like the data never got copied into the database that was in my project.

I did a search all over google and came up with nothing.  And now that I’ve discovered what the answer is, I remember that I had this exact same issue several month ago when I first started using Visual Studio 2008 on another Windows Forms application.  So, this post is first, to help me remember and second, to help anyone else who might be having this problem.

When Visual Studio compiles the application, it copies what ever database you have in the project into the directory that the exe is in.  This means that what ever data you have in the database at the project level is what you will see when you run the application.

My solution to this behavior was to change the connection string in app.config so that the database being used is the one in the project and not the one in the exe directory.

Hope this helps someone.

Related Post

  • VB.NET Processing Before WinForm DisplayVB.NET Processing Before WinForm Display I woke up this morning to an interesting question. “Using VB.net 2008, I want my project to be a Windows Forms Application, but upon startup, I want to check a few files to see if they exist and...
  • Windows Forms – Passing Parameters at RuntimeWindows Forms – Passing Parameters at Runtime I received the following question over the weekend: I've made a C# form application and I need to send a report name at runtime. How do I add an incoming parameter to the command line? Such as "c...
  • One Form with Multiple TablesOne Form with Multiple Tables I received the following question a few days ago: “I am trying to use three tables from the same dataset in one form that I am creating in vs.net winforms my problem I guess is the setup of it as ...
  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it wrong, which...
  • WinForms – Change The Active TabWinForms – Change The Active Tab This question came in last Friday: I'm trying to code a windows form in vb.net 2005. In my form I have 2 TabControls and a command button. The button is in the first TabControl, so what I want to...