Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Question on Lesson 9 -Databinding Data to User Interface Controls
 

Question on Lesson 9 -Databinding Data to User Interface Controls

Hello again,

I have been working through these c sharp lessons and they are great!

There is one lesson that I have a question on is lesson 9 and I am not sure if this is the right place to post the question, but here is the link to the project.

http://msdn2.microsoft.com/en-us/vstudio/Aa700773.aspx

I worked through this lesson three times and I can not figure out one thing.

When the project runs in real-time and the data is changed(add, delete, change) and then save, the data is reflected to the activeForm(s).

But when I close the project and look at the database within the project, the changes did not store in the database, am I missing something?

Dave

dpsolsys  Wednesday, November 28, 2007 9:17 PM

ok maybe you were looking in the wrong debug folder

There are 2 of these also in your app

1 in the obj directory

and also 1 in the bin directory

you want the one that is in the bin directory

Jeff - www.SRSoft.us  Saturday, December 01, 2007 7:54 PM

I think it should be the same in c# as vb

solution explorer - right click on your database file (.mdf)

click properties

set copy to output directory to copy if newer

Jeff - www.SRSoft.us  Friday, November 30, 2007 3:29 AM

Hi,I tried it in the solution Explorer and run the program.

I made changes and save. Exited out the program, looked into the Database and it did not take effect.

any other thoughts?

dpsolsys  Friday, November 30, 2007 2:51 PM

Ok, i think i misunderstood what you meant

you are looking at the database by showing the data in the designer

There are 2 database files in your project

1 in the main directory and 1 in the debug folder

the one you are using at runtime is in the debug folder

you can manually connet to it in the database explorer

right click on data connections

click add connection

then follow the menus and navigate to your poject debug folder and connect to the database

this will allow you to see the data in it

The other thing you can do also is to adda new form to your project

go to the data sources window (data menu) - show data sources

then drag the table you want to view over to the form

this will show you a gridview of it

you can open the form with a button on your form 1 with code\

or set it as your startup form in your project properties

Jeff - www.SRSoft.us  Friday, November 30, 2007 3:46 PM

In the project file I see 1 database file (.mdf) in the main diectory. I did check the debug folder and there is no .mdf file in the folder.

But I did reconnect the database that is in the main directory and tested the connection, which was successful.

Ran the program and make and save changes. Close the program and in designer there is still no changes to the database.

I did create another form and did drag the database to the form and the data was still the same.

I am mistified by this. Is there another C Charp Database tutorial that I can try that someone knows?

dpsolsys  Friday, November 30, 2007 4:03 PM

Not sure. I think the designer works with its own copy of things and recreates them each time you rebuild so changes are lost. There may be a way to shut this off but I have not looked.

I'd be interested to know the solution.

greenhouse  Friday, November 30, 2007 6:43 PM

ok maybe you were looking in the wrong debug folder

There are 2 of these also in your app

1 in the obj directory

and also 1 in the bin directory

you want the one that is in the bin directory

Jeff - www.SRSoft.us  Saturday, December 01, 2007 7:54 PM

greenhouse,

the only way i know of to prevent this from happening is to force it to work with only one database. Or just use the above example of changing the copy to output directory to copy if newer.

There are several things you can do

when you create a new database, it automatically adds it to your project

this is where the 2 are created

if you were to use a blank project or sql server management studio express to create the database

then you can take that database from either the project of studio express and then add it to your "real" project folder by copying and pasting. you could use the add existing item in the project menu to "add" the database to your project and you would have to specify it to not copy the database. This would connect to it where it currently is. The drawback for someone like me is that i make a copy of my project everyday with the day's date and i work with that one for that particular day. Then the next day i do the same. This gives me a new copy everyday and i have backups from everyday. This lets me keep track of my progress and incase i mess something up i only have lost a day or i can go back a day and then see where i went wrong. So the problem is that when you open the new copied project you have to re-connect to the database again inyour data sourcesbecause it will be looking in the original folder. That is ok of you have the database in a relative directory that you plan on leaving it in the entire testing time like in your c:\ directory. But i like to have a backup of my database everyday also. I have had them get corrupted before like tables mysteriously dissappering.

So you can figure out what works best for you on that one.

The other option is to work with the database strictly in code. Connections, objects, queries, everything. That is what i do now. And i have my connection string coded to look at my bin debug folder automatically for every copied project using application.startuppath as the path. This will find the startup directory and look for it there.

Hope this helps

Jeff - www.SRSoft.us  Tuesday, December 04, 2007 2:16 PM

You can use google to search for other answers

Custom Search

More Threads

• Inserting row into user sorted, data-bound DataGridView
• Turn 1 ID column into two columns from another table.
• Get the current Coloum / Header
• Datagridview / Stored Procedure
• Binding a List<UInt32> object to a DataViewGrid
• Datagrid Problem using MDI forms.
• How to reflect datagrid changes
• Repeater for windows forms
• DataGridViewComboBoxCell error
• Multiple tables data in dataGrid