473,599 Members | 3,118 Online
Bytes | Software Development & Data Engineering Community
+ 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 "Walkthroug h: 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
CustomersTableA dapter. By default, an event handler for the
BindingNavigato r'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 BindingNavigato r to open the
Code Editor to the bindingNavigato rSaveItem_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.customersB indingSource.En dEdit();
this.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
MessageBox.Show ("Update successful");
}
catch (System.Excepti on 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.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
doesn't update the customer table in the northwind database.

//Tony

Oct 23 '07 #1
2 2380
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.com wrote in message
news:uL******** ******@TK2MSFTN GP03.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 "Walkthroug h: 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
CustomersTableA dapter. By default, an event handler for the
BindingNavigato r'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 BindingNavigato r to open the
Code Editor to the bindingNavigato rSaveItem_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.customersB indingSource.En dEdit();
this.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
MessageBox.Show ("Update successful");
}
catch (System.Excepti on 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.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
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******** *****@TK2MSFTNG P06.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.com wrote in message
news:uL******** ******@TK2MSFTN GP03.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 "Walkthroug h: 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
CustomersTableA dapter. By default, an event handler for the
BindingNavigato r'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 BindingNavigato r to open the
Code Editor to the bindingNavigato rSaveItem_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.customersB indingSource.En dEdit();
this.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
MessageBox.Show ("Update successful");
}
catch (System.Excepti on 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.customersT ableAdapter.Upd ate(this.northw indDataSet.Cust omers);
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
1381
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 i want to understand how this works. ---------------------------------------------- #file1.py
1
1608
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 ('database'); Empty set (0.00 sec) mysql> SELECT id, MATCH (title,body) AGAINST ('Tutorial') -> FROM articles; +----+-----------------------------------------+
1
2861
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 http://www.codeproject.com/csharp/CsManagedEventSinksHooks.as So far so good....except when it comes down to binding the component to the folder on the Exchange Store. When I do...I get the following error
105
5280
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 not work. It only works on lists and strings, for no obvious reason. Why not on all sequence types? Or, another example, the index() method has start and end parameters for lists and strings. The count() method also has start and end parameters...
2
2189
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
2640
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 be run, say from windows the "run" function? 3) are most of you doing your script editing in IDLE or something more fully featured? 4) how are you importing previously written blocks of code into your
31
1708
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 first character numbered 0. Then the right edge of the last character of a string of n characters has index n, for example: +---+---+---+---+---+ | H | e | l | p | A |
6
1585
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 $username="root"; // Mysql username
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 (Single Table)" You must have access to the Northwind sample database.
5
1347
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 just keeps trying to load until it times out. I would like to know how to send information through the server to my browser? I was working through this tutorial: http://python.about.com/od/networkingwithpython/ss/PythonWebServer.htm
0
7992
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8400
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.