List Info

Thread: Save data to database




Save data to database
user name
2006-09-05 16:22:30
This is nothing more than a guess, try something like this.

Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.[name])

-----Original Message-----
From: Discussion of writing applications and components
using Visual
Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of King,
Michael A
Sent: Sunday, September 03, 2006 19:28
To: VBDOTNETDISCUSS.DEVELOP.COM
Subject: [VBDOTNET] Save data to database


Hello,

Please forgive me if this is a really obvious question.

I am just starting to explore Visual Studio 2005 and am
having a problem
saving records to a database. I have created a very simple
project using
1 form and I set up a database using the create new
datasource wizard. I
created 1 table (by right clicking on the tables folder in
the server
explorer window)

I then simply dragged the table from the Data Sources window
onto my
form where it created a grid for me along with a navigator,
table
adaptor, etc.

Here is the total code:

Public Class Form1

    Private Sub NameBindingNavigatorSaveItem_Click(ByVal
sender As
System.Object, ByVal e As System.EventArgs) Handles
NameBindingNavigatorSaveItem.Click
        Try
            Me.Validate()
            Me.NameBindingSource.EndEdit()
           
Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.name)
            MsgBox("Saved successfully")
        Catch ex As Exception
            MsgBox("Problem saving")
        End Try

    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
'TestDatabaseDataSet.name' table. You can move, or remove
it, as needed.
       
Me.NameTableAdapter.Fill(Me.TestDatabaseDataSet.name)

    End Sub
End Class

When I run the project, I can enter data in the fields, I
click the save
button and get the msg that the save is successful. 
However, if I close
the application and the restart it, the data is not
displayed. I checked
using the "show table data" menu when I right
click the table in the
server explorer window and it also shows no data.

Can someone point out what I am not doing correctly?

Thanks,

Michael K.

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Save data to database
user name
2006-09-05 23:59:30
Bill,
Thanks for the suggestion, but that is what I am doing.  I
have confused
it a bit with my table name which is actually
"name".
Cheers, 


Michael King
> 
>*Phone: 08 8282 4440
>

-----Original Message-----
From: Discussion of writing applications and components
using Visual
Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of Booth,
Bill
Sent: Wednesday, 6 September 2006 1:53 AM
To: VBDOTNETDISCUSS.DEVELOP.COM
Subject: Re: [VBDOTNET] Save data to database

This is nothing more than a guess, try something like this.

Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.[name])

-----Original Message-----
From: Discussion of writing applications and components
using Visual
Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of King,
Michael A
Sent: Sunday, September 03, 2006 19:28
To: VBDOTNETDISCUSS.DEVELOP.COM
Subject: [VBDOTNET] Save data to database


Hello,

Please forgive me if this is a really obvious question.

I am just starting to explore Visual Studio 2005 and am
having a problem
saving records to a database. I have created a very simple
project using
1 form and I set up a database using the create new
datasource wizard. I
created 1 table (by right clicking on the tables folder in
the server
explorer window)

I then simply dragged the table from the Data Sources window
onto my
form where it created a grid for me along with a navigator,
table
adaptor, etc.

Here is the total code:

Public Class Form1

    Private Sub NameBindingNavigatorSaveItem_Click(ByVal
sender As
System.Object, ByVal e As System.EventArgs) Handles
NameBindingNavigatorSaveItem.Click
        Try
            Me.Validate()
            Me.NameBindingSource.EndEdit()
           
Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.name)
            MsgBox("Saved successfully")
        Catch ex As Exception
            MsgBox("Problem saving")
        End Try

    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
'TestDatabaseDataSet.name' table. You can move, or remove
it, as needed.
       
Me.NameTableAdapter.Fill(Me.TestDatabaseDataSet.name)

    End Sub
End Class

When I run the project, I can enter data in the fields, I
click the save
button and get the msg that the save is successful. 
However, if I close
the application and the restart it, the data is not
displayed. I checked
using the "show table data" menu when I right
click the table in the
server explorer window and it also shows no data.

Can someone point out what I am not doing correctly?

Thanks,

Michael K.

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com


===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Save data to database
user name
2006-09-06 10:58:57
Michael,
The database file in your root project folder is only
changed when you
edit the database schema or data using Server
Explorer/Database Explorer
or other Visual Database Tools.

The relationship between the two versions of your database
file is
dependent on the setting of the Copy to Output Directory
property, which
is described in the table below.

During application development, any changes made to the data
(during run
time within your application) are being made to the database
in the bin
folder. For example, when you press F5 to debug your
application, you
are connected to the database in the bin folder.

from:
http://msdn2.microsoft.com/en-us/library/ms246989.aspx

DaveM

> -----Original Message-----
> From: Discussion of writing applications and components
using Visual
> Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of King,
> Michael A
> Sent: Sunday, September 03, 2006 19:28
> To: VBDOTNETDISCUSS.DEVELOP.COM
> Subject: [VBDOTNET] Save data to database
>
>
> Hello,
>
> Please forgive me if this is a really obvious question.
>
> I am just starting to explore Visual Studio 2005 and am
having a problem
> saving records to a database. I have created a very
simple project using
> 1 form and I set up a database using the create new
datasource wizard. I
> created 1 table (by right clicking on the tables folder
in the server
> explorer window)
>
> I then simply dragged the table from the Data Sources
window onto my
> form where it created a grid for me along with a
navigator, table
> adaptor, etc.
>
> Here is the total code:
>
> Public Class Form1
>
>     Private Sub
NameBindingNavigatorSaveItem_Click(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> NameBindingNavigatorSaveItem.Click
>         Try
>             Me.Validate()
>             Me.NameBindingSource.EndEdit()
>            
Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.name)
>             MsgBox("Saved successfully")
>         Catch ex As Exception
>             MsgBox("Problem saving")
>         End Try
>
>     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
> 'TestDatabaseDataSet.name' table. You can move, or
remove it, as needed.
>        
Me.NameTableAdapter.Fill(Me.TestDatabaseDataSet.name)
>
>     End Sub
> End Class
>
> When I run the project, I can enter data in the fields,
I click the save
> button and get the msg that the save is successful. 
However, if I close
> the application and the restart it, the data is not
displayed. I checked
> using the "show table data" menu when I
right click the table in the
> server explorer window and it also shows no data.
>
> Can someone point out what I am not doing correctly?
>
> Thanks,
>
> Michael K.
>
>
>


===
David Mekelburg

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Save data to database
user name
2006-09-06 23:39:44
Thank You David,

Now I understand what is happening.  I was changing the data
in the db
in the bin folder. When I press F5 to run the app again, the
file from
the root folder (which is empty) was being copied over the
db in the bin
folder. Hence no retained records.

If I run the executable from the bin folder - bingo! All
works as
expected.

Appreciate your help. 


Michael King
> 
>*Phone: 08 8282 4440
>

-----Original Message-----
From: Discussion of writing applications and components
using Visual
Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of David
Mekelburg
Sent: Wednesday, 6 September 2006 8:29 PM
To: VBDOTNETDISCUSS.DEVELOP.COM
Subject: Re: [VBDOTNET] Save data to database

Michael,
The database file in your root project folder is only
changed when you
edit the database schema or data using Server
Explorer/Database Explorer
or other Visual Database Tools.

The relationship between the two versions of your database
file is
dependent on the setting of the Copy to Output Directory
property, which
is described in the table below.

During application development, any changes made to the data
(during run
time within your application) are being made to the database
in the bin
folder. For example, when you press F5 to debug your
application, you
are connected to the database in the bin folder.

from:
http://msdn2.microsoft.com/en-us/library/ms246989.aspx

DaveM

> -----Original Message-----
> From: Discussion of writing applications and components
using Visual 
> Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of King, 
> Michael A
> Sent: Sunday, September 03, 2006 19:28
> To: VBDOTNETDISCUSS.DEVELOP.COM
> Subject: [VBDOTNET] Save data to database
>
>
> Hello,
>
> Please forgive me if this is a really obvious question.
>
> I am just starting to explore Visual Studio 2005 and am
having a 
> problem saving records to a database. I have created a
very simple 
> project using
> 1 form and I set up a database using the create new
datasource wizard.

> I created 1 table (by right clicking on the tables
folder in the 
> server explorer window)
>
> I then simply dragged the table from the Data Sources
window onto my 
> form where it created a grid for me along with a
navigator, table 
> adaptor, etc.
>
> Here is the total code:
>
> Public Class Form1
>
>     Private Sub
NameBindingNavigatorSaveItem_Click(ByVal sender As 
> System.Object, ByVal e As System.EventArgs) Handles 
> NameBindingNavigatorSaveItem.Click
>         Try
>             Me.Validate()
>             Me.NameBindingSource.EndEdit()
>            
Me.NameTableAdapter.Update(Me.TestDatabaseDataSet.name)
>             MsgBox("Saved successfully")
>         Catch ex As Exception
>             MsgBox("Problem saving")
>         End Try
>
>     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 
> 'TestDatabaseDataSet.name' table. You can move, or
remove it, as
needed.
>        
Me.NameTableAdapter.Fill(Me.TestDatabaseDataSet.name)
>
>     End Sub
> End Class
>
> When I run the project, I can enter data in the fields,
I click the 
> save button and get the msg that the save is
successful.  However, if 
> I close the application and the restart it, the data is
not displayed.

> I checked using the "show table data" menu
when I right click the 
> table in the server explorer window and it also shows
no data.
>
> Can someone point out what I am not doing correctly?
>
> Thanks,
>
> Michael K.
>
>
>


===
David Mekelburg

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )