Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with C# and SQL: Table doesn't keep data

Status
Not open for further replies.

carlossan

Programmer
Dec 10, 2005
18
CA
Hello,

I created a SQL DB with a single table using C# 2005 Express and SQL Express, and after doing that I dragged the table to a form to create the datagrid. Up to that point everything was working fine.

The problem I have is that I can’t save information in that table by using my application, because every time that I run my project, the table appears empty.

When I publish the project, and I run the application from the .exe file, this problem disappears, and I can add data to the table via my application and the data stays in the table so I see the entered data every time I run the application.

Any idea about what is happening?

Thanks,

Carlos
 
Probably the reason is the following:

You've got the database in a folder. When you run the app from the IDE, that database is copied into the bin\debug folder and the app uses that database to save data.

Now when you close and run the app again, the first database is again copied into the bin\debug directory, and overwrites the previous one (where you had saved the tables).

As a solution you can select the database.mdf from the solution explorer, and from the properties, set Copy To Output Directory to 'Do Not Copy'.

ABC -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top