Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Easy question about a not working tutorial about ado.net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TonyJ - 23 Oct 2007 08:30 GMT
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.northwindDataSet.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.northwindDataSet.Customers);
doesn't update the customer table in the northwind database.

//Tony
Ged - 23 Oct 2007 08:50 GMT
Hi Tony

I've just ran through the steps you've listed (also found here
http://msdn2.microsoft.com/en-us/library/0f92s97z(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.

Signature

Ged Moretta
www.appsense.com

-----------------------------------------------------------------------
This signature isn't automatic. I have to type it manually every time.

> Hello!
>
[quoted text clipped - 74 lines]
>
> //Tony
TonyJ - 23 Oct 2007 09:46 GMT
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

> Hi Tony
>
[quoted text clipped - 54 lines]
> >        this.Validate();
> >        this.customersBindingSource.EndEdit();

this.customersTableAdapter.Update(this.northwindDataSet.Customers);
> >        MessageBox.Show("Update successful");
> >    }
[quoted text clipped - 27 lines]
> >
> > //Tony

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.