473,480 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Easy question about a not working tutorial about ado.net

Hello!

I use VS2005 and C#.
I'm looking at ADO.NET and have found some test tutorial on
microsoft MSDN.

It can be found on google when searching for "Walkthrough: Saving Data to a
Database (Single Table)"
You must have access to the Northwind sample database.

I have followed the walkthrought in this tutorial exectly but it doesn't
save data back to the worthwind database as the tutorial say.

The tutorial say the following.
1. Create a project

2. Create a Data Source by using the Northwind database table customer

3. To set the controls for the items in the Data Sources window.
Expand the Customers node in the Data Sources window.
Change the control for the Customers table to individual controls by
selecting Details from the drop-down list on the Customers node.

4. Create data-bound controls on the form
Drag the main Customers node from the Data Sources window onto
Form1.

5. Modifying the Code to Update the Database
You can update the database by calling the Update method of the
CustomersTableAdapter. By default, an event handler for the
BindingNavigator's Save button is added to the form's code to send
updates to the database. This procedure modifies the code to include
error
handling by wrapping the update call in a try-catch block.
You can modify the code to suit the needs of your application.

6. To add update logic to the application
Double-click the Save button on the BindingNavigator to open the
Code Editor to the bindingNavigatorSaveItem_Click event handler.
Replace the code in the event handler to add some error handling.
The code should look like the following:
try
{
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}

7. Testing the Application
Press F5.
Note here Update successful is written so everything seems normal.
Make some changes to the data of one or more records.
Press the Save button.(It's a diskett icon)
Check the values in the database to verify that the changes were saved.

So I do the following change some data in one of the control(text field)
and then click the diskett
icon meaning I saving the data back to the database. If I now go to the next
record and then go back to the previous record the change is there. So I
manage to change in the dataset but if I then close the application and look
in the database my changes has not changed anything in the database.I can't
understand why this doesn't work.
Is this a bug perhaps. I would be very glad if someone have any comment
about my problem.
Is it possible to trace in some way why this row
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
doesn't update the customer table in the northwind database.

//Tony

Oct 23 '07 #1
2 2364
Hi Tony

I've just ran through the steps you've listed (also found here
http://msdn2.microsoft.com/en-us/lib...7z(VS.80).aspx) and I've had
no problems.

Are you sure that the database you connect to when checking the changed
values, is the same one you connected to from Visual Studio ?
(You can check the database settings in the App.Config file)
That's the only reason I can think of that would produce the results you are
seeing.
--
Ged Moretta
www.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.
"TonyJ" <jo*****************@telia.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
Hello!

I use VS2005 and C#.
I'm looking at ADO.NET and have found some test tutorial on
microsoft MSDN.

It can be found on google when searching for "Walkthrough: Saving Data to
a
Database (Single Table)"
You must have access to the Northwind sample database.

I have followed the walkthrought in this tutorial exectly but it doesn't
save data back to the worthwind database as the tutorial say.

The tutorial say the following.
1. Create a project

2. Create a Data Source by using the Northwind database table customer

3. To set the controls for the items in the Data Sources window.
Expand the Customers node in the Data Sources window.
Change the control for the Customers table to individual controls by
selecting Details from the drop-down list on the Customers node.

4. Create data-bound controls on the form
Drag the main Customers node from the Data Sources window onto
Form1.

5. Modifying the Code to Update the Database
You can update the database by calling the Update method of the
CustomersTableAdapter. By default, an event handler for the
BindingNavigator's Save button is added to the form's code to send
updates to the database. This procedure modifies the code to include
error
handling by wrapping the update call in a try-catch block.
You can modify the code to suit the needs of your application.

6. To add update logic to the application
Double-click the Save button on the BindingNavigator to open the
Code Editor to the bindingNavigatorSaveItem_Click event handler.
Replace the code in the event handler to add some error handling.
The code should look like the following:
try
{
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}

7. Testing the Application
Press F5.
Note here Update successful is written so everything seems normal.
Make some changes to the data of one or more records.
Press the Save button.(It's a diskett icon)
Check the values in the database to verify that the changes were saved.

So I do the following change some data in one of the control(text field)
and then click the diskett
icon meaning I saving the data back to the database. If I now go to the
next
record and then go back to the previous record the change is there. So I
manage to change in the dataset but if I then close the application and
look
in the database my changes has not changed anything in the database.I
can't
understand why this doesn't work.
Is this a bug perhaps. I would be very glad if someone have any comment
about my problem.
Is it possible to trace in some way why this row
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
doesn't update the customer table in the northwind database.

//Tony
Oct 23 '07 #2
Hello!

I found my problem.

When I created the connection to the database I was asked if I wanted to
copy the database file to my project.
Here I answered Yes. The default settings for the copied database into my
project was copy always.
Copy always mean that a copy is made from the project root directory to the
output bin directory everytime you run the program.
This means that I really changed my database in the output bin dirctory but
when I ran the applictiopn for the second time the database from the project
root directory was copied to my output bin directory overwriting my changes.

//Tony

<Gedskrev i meddelandet news:eC*************@TK2MSFTNGP06.phx.gbl...
Hi Tony

I've just ran through the steps you've listed (also found here
http://msdn2.microsoft.com/en-us/lib...7z(VS.80).aspx) and I've
had
no problems.

Are you sure that the database you connect to when checking the changed
values, is the same one you connected to from Visual Studio ?
(You can check the database settings in the App.Config file)
That's the only reason I can think of that would produce the results you
are
seeing.
--
Ged Moretta
www.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.
"TonyJ" <jo*****************@telia.comwrote in message
news:uL**************@TK2MSFTNGP03.phx.gbl...
Hello!

I use VS2005 and C#.
I'm looking at ADO.NET and have found some test tutorial on
microsoft MSDN.

It can be found on google when searching for "Walkthrough: Saving Data
to
a
Database (Single Table)"
You must have access to the Northwind sample database.

I have followed the walkthrought in this tutorial exectly but it doesn't
save data back to the worthwind database as the tutorial say.

The tutorial say the following.
1. Create a project

2. Create a Data Source by using the Northwind database table customer

3. To set the controls for the items in the Data Sources window.
Expand the Customers node in the Data Sources window.
Change the control for the Customers table to individual controls by
selecting Details from the drop-down list on the Customers node.

4. Create data-bound controls on the form
Drag the main Customers node from the Data Sources window onto
Form1.

5. Modifying the Code to Update the Database
You can update the database by calling the Update method of the
CustomersTableAdapter. By default, an event handler for the
BindingNavigator's Save button is added to the form's code to send
updates to the database. This procedure modifies the code to include
error
handling by wrapping the update call in a try-catch block.
You can modify the code to suit the needs of your application.

6. To add update logic to the application
Double-click the Save button on the BindingNavigator to open the
Code Editor to the bindingNavigatorSaveItem_Click event handler.
Replace the code in the event handler to add some error handling.
The code should look like the following:
try
{
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}

7. Testing the Application
Press F5.
Note here Update successful is written so everything seems normal.
Make some changes to the data of one or more records.
Press the Save button.(It's a diskett icon)
Check the values in the database to verify that the changes were saved.

So I do the following change some data in one of the control(text field)
and then click the diskett
icon meaning I saving the data back to the database. If I now go to the
next
record and then go back to the previous record the change is there. So I
manage to change in the dataset but if I then close the application and
look
in the database my changes has not changed anything in the database.I
can't
understand why this doesn't work.
Is this a bug perhaps. I would be very glad if someone have any comment
about my problem.
Is it possible to trace in some way why this row
this.customersTableAdapter.Update(this.northwindDa taSet.Customers);
doesn't update the customer table in the northwind database.

//Tony


Oct 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
1369
by: fred.dixon | last post by:
i have read the book and searched the group too ---------------------------------------------- im not gettin it. i want to read a global (OPTIONS) from file1 from a class method (func1) in file2...
1
1596
by: Mike Reef | last post by:
I'm trying fulltext searching for the first time , but I can't figure out why the example in the mySQL manual is *not* working. mysql> SELECT * FROM articles -> WHERE MATCH (title,body) AGAINST...
1
2852
by: Notlwonk | last post by:
Not sure where to post this Q I am trying to write a Managed Exchange Server Event Sink (as a class library) in C# I have been following this tutorial step-by-step ...
105
5223
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does...
2
2187
by: Dheroyan2006 | last post by:
I have made a site for easy c programming tutorial very easy to learn click here www.geocities.com/sahfeie/electronics
14
2630
by: Omar | last post by:
1) why don't python / idle use numbered lines in their scripting, like basic? how do you keep track of large batches of code without them? 2) in IDLE, how do you save a program such that it can...
31
1689
by: Antoon Pardon | last post by:
The following is part of the explanation on slices in the tutorial: The best way to remember how slices work is to think of the indices as pointing between characters, with the left edge of the...
6
1581
by: punitshrivastava | last post by:
Hi all, I am Punit I am working in php .i want to delete records from database from php form . For this i code the code is: <?php $name = $_POST; $host="localhost"; // Host name ...
0
231
by: TonyJ | last post by:
Hello! I use VS2005 and C#. I'm looking at ADO.NET and have found some test tutorial on microsoft MSDN. It can be found on google when searching for "Walkthrough: Saving Data to a Database...
5
1337
by: fishfin | last post by:
I was working through a tutorial about how to write a server using python (the url is bellow). I am sure that the server is working to some degree because when the server is running localhost:8080...
0
7046
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7088
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.