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.
- VB.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 […]
- Windows 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? […]
- One 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 […]
- DotNetNuke 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 […]
- Getting started with jQuery and ASP.NET As promised, I am starting a series on jQuery. Today our goal is to get a project setup in Visual Studio that uses jQuery. We won't be explaining much in the way of syntax, but we will […]
About Dave Bush