Need help updating database

daveofgv

Well-known member
Joined
Sep 17, 2008
Messages
218
Location
Dallas, TX
Programming Experience
1-3
I have a windows form and I created a SQL database within the project.

To fill the controls visual studio 2008 pro adds the fill for you:

VB.NET:
Expand Collapse Copy
Me.PersonalTableAdapter.Fill(Me.Personaldataset.personal)

I can get the combobox to show the data, labels, datagrid etc.....

NOW:

I can update the datagrid and other controls with:

VB.NET:
Expand Collapse Copy
PersonalTableAdapter.Update(Personaldataset)

but when I look inside the database (and refresh) it is not updated............

Can anyone tell me why??????

How do I update the actual database so when I look into it the info i just added in the datagrid is there???

thanks

daveofgv
 
Assuming that there are actually changes in your data, you're looking at the wrong database. First up, check the value returned by Update. If it's not zero then the changes were saved. In that case, follow the first link in my signature to learn how local data files are managed.
 
Awsome! When I first read your reply I had a bunch of words that came to mind....lol.... I was saying who does this guy think he is.... I know I am pointing to the correct database since I just added it in my project... I'm not that big of a moron...... Then I read the link you provided and noticed that my data that I added was in the database (bin) folder and not in the root directory (which is where my program is pointing to).........

What stinks though if it stays like this then you will never know if your program is working since it is not connected correctly and always copies............

Thanks for the info and help.....That was an awsome link.....

Now off to programming..
 
Quick question - after I connect to the "correct" database - should each table have a different dataset? Or should I just use one dataset for all?
 
Working with local data files is actually very easy, and nothing sticks. Here's how it works:

You add the database to your project in the Solution Explorer. The file gets added to the project folder, along with all the other source files.

You use this source data file only at design time. You edit that file to create the schema and also to add initial/default data ONLY. Your application DOES NOT connect to that database at all. Your application doesn't even know that that database exists.

You use |DataDirectory| in your connection string to represent the folder containing the data file. While debugging, that will be the same folder that contains the EXE.

When you build your project for debugging, the EXE is output to bin\Debug folder and the data file is copied to that location also. It is that database that your application connects to, courtesy of the |DataDirectory| place-holder.

As I said, you can use the result of Update to determine whether data was saved, so you know from that whether your app is working. Apart from that, as the link I provided explains, you can also set the Copy To Output Directory property of the data file to Copy If Newer. In that case, the original data file is only copied to the output folder when you build if you have made changes to the original. That allows you to run multiple sessions using the same data in your debugging database.
 
Back
Top