Adding data to database

T

trevor.niemack

Hello
I am currently learning VB.net and I am using the tutorial on VB
express. One of the tutorials is about adding a database and then
creating a visual input or amendment screen but event though I have
followed the tutorial and even redone all the steps I cannot get the
input to save into the data below is the code that currently exists
against the form.

Public Class Form1

Private Sub AddressBookBindingNavigatorSaveItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
AddressBookBindingNavigatorSaveItem.Click
Me.Validate()
Me.AddressBookBindingSource.EndEdit()

Me.AddressBookTableAdapter.Update(Me.Database1DataSet.AddressBook)


End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Me.AddressBookBindingSource.EndEdit()

Me.AddressBookTableAdapter.Update(Me.Database1DataSet.AddressBook)


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'Database1DataSet.AddressBook' table. You can move, or remove it, as
needed.

Me.AddressBookTableAdapter.Fill(Me.Database1DataSet.AddressBook)

End Sub
End Class
 
G

gene kelley

Hello
I am currently learning VB.net and I am using the tutorial on VB
express. One of the tutorials is about adding a database and then
creating a visual input or amendment screen but event though I have
followed the tutorial and even redone all the steps I cannot get the
input to save into the data below is the code that currently exists
against the form.

Public Class Form1

Private Sub AddressBookBindingNavigatorSaveItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
AddressBookBindingNavigatorSaveItem.Click
Me.Validate()
Me.AddressBookBindingSource.EndEdit()

Me.AddressBookTableAdapter.Update(Me.Database1DataSet.AddressBook)


End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Me.AddressBookBindingSource.EndEdit()

Me.AddressBookTableAdapter.Update(Me.Database1DataSet.AddressBook)


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'Database1DataSet.AddressBook' table. You can move, or remove it, as
needed.

Me.AddressBookTableAdapter.Fill(Me.Database1DataSet.AddressBook)

End Sub
End Class


Run the .exe file in the project's bin\debug folder a couple of times.
You should see saved changes.

The two lines in the FormClosing event are not necessary.

Gene
 
T

trevor.niemack

Hello Gene
Thank you for the help but could you probably give me a short
explaination as to why if I run the exe from with the bin/debug folder
will the changes be saved whereas if I do this from within the IDE the
changes do not get saved?
I did read something about the properties option to copy to output
directory that will allow the changes to be saved.
 
G

gene kelley

Hello Gene
Thank you for the help but could you probably give me a short
explaination as to why if I run the exe from with the bin/debug folder
will the changes be saved whereas if I do this from within the IDE the
changes do not get saved?
I did read something about the properties option to copy to output
directory that will allow the changes to be saved.

The changes do actually get saved when running from within the IDE.
However, by default, the database file's property, Copy To Output
Directory, is "Copy Always". So, each time you run the project in the
IDE, the last working database file in the bin/debug folder gets
overwritten with the original database file, hence, it appears that
previous changes were not saved. The same applies with builds. Each
time you make a build, the original database file is copied to the
bin/release folder.

Changing "Copy Always" to Copy If Newer" will allow saved changes to
show when running in the IDE unless changes are made to the original
database file. If you are going to distribute the app, you need to
keep in mind whether you want the original or "current" database file
in the release.

Gene
 
T

trevor.niemack

Hello Gene
I do understand the concept and I have got it to work and as you
mentioned in your last statement the original database is being viewed
instead of the current. How can I change this?
Thanks for you time and help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top