Wrox Programmer Forums
|
BOOK: Wrox's SQL Server 2005 Express Edition Starter Kit ISBN: 978-0-7645-8923-2
This is the forum to discuss the Wrox book Wrox's SQL Server 2005 Express Edition Starter Kit by Rajesh George, Lance Delano; ISBN: 9780764589232
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Wrox's SQL Server 2005 Express Edition Starter Kit ISBN: 978-0-7645-8923-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 17th, 2006, 06:56 AM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Master-Detail, Chapter 4 - Not updating in C#

Hello!

Go I little further and this is my update code under a button in the form. The database is not Updated, at least I cannot see any new records when firing up the application again.

Here is my code:
private void button1_Click(object sender, EventArgs e){
            this.bookBindingSource.EndEdit();
            this.personBindingSource.EndEdit();

            try{
                MessageBox.Show("Going to update!");

// Delete records in the child table
this.bookTableAdapter.Update(this.myDBDataSet1.Boo k.Select("", "",DataViewRowState.Deleted));

// Handle Add, Update, and Delete in parent table
this.personTableAdapter.Update(this.myDBDataSet1.P erson.Select("", "", DataViewRowState.Added) );

// Handle Add & Update in child table
this.bookTableAdapter.Update(this.myDBDataSet1.Boo k.Select("", "", DataViewRowState.Added ) );

            }
            catch ( Exception exception){
                MessageBox.Show(exception.Message);

            }
            MessageBox.Show("Database updated!");
        }

The code complains using the DataViewRowState.Added and the '||'

Anyone care to try this out with C# !?

regards, i


 
Old March 17th, 2006, 02:32 PM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi inkimar,

I'm having the same problem. Tried both VB and C# but DB does not update. The MyDBDataSet does update but results are not stored in the DB. I downloaded and tried the MasterDetail source from Wrox and that didn't work either. Unfortunately, I can't tell why update fails.

FWIW I just discovered the delete key removes rows from Book. I spent all day yesterday trying to find why the tool strip X deleted all records for a particular AuthorID instead of just a row!

These examples and exercises appear to be hastily put together. Some are hard to follow, others just don't work.

Sturdy

 
Old March 19th, 2006, 07:04 AM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sturdy!

oh, that is quite a blow, I want to move with a rapid pace here.
Just switched from java to C# in my latest projekt.

If I find any solution I will write it down here, one should
try to contact wrox - I will submit an errata.

regards, i

 
Old March 19th, 2006, 04:27 PM
Authorized User
 
Join Date: Dec 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A lot of people, including me, have wasted a lot of time trying to get the Master-Detail Form to update. The thing is that the exercise does work but due to a nice little feature from our friends at Microsoft we just don't get to see it.

When following the Try-It-Out on page 66 have a look, via Windows Explorer, at the folders where you have your project. You will see that there are two database (.mdf) files. One in the Project folder and one under the bin/debug (output) folder. When you update the table as instructed it is the output folder that is used, However during design time it is the version used in the Project folder that is used.

Now comes the clever bit. Each time you build the project the version of the database in the output file (i.e. the one you have updated) is overwritten by the one in the Project folder (i.e. the original version). Hence you don't get to see your changes.

There are a couple of recommended work arounds:
1. I've tried this one and it works
a. Select the database in Solution Explorer
b. Locate the 'Copy to Output' property in the Properties window
c. Change it from 'Copy always' to 'Do not copy'
d. If necessary manually copy the database (.mdf) file to the output (bin/debug) folder
On future builds the version in the output folder will not be overwritten with the one in the project folder.

Now I haven't got this far but apparently if you want to modify the database in design time then you will need to manually copy the one in the output file to the project and vice versa.

2. Someone has also suggested that you can do this and I hae used it in conjunction with number 1. above
a. In Database Explorer right-click on the database
b. Select Modify Connection
c. Select Advanced options
d. Search for the property AttachDbFileName
e. Point it to the bin/debug version
The thing to bear in mind is that it only works in Debug mode


3. Another recommended work around
a. Leave the database outside of the project
b. Create a connection to it in Database Explorer
c. When the IDE asks you to bring it into the project just say no
Now the design and run-time versions point to the same database file. The downside to this method is that the connection string will be effectively hard-coded making it more of a problem when you come to deploy the application. Before deploying the application it would probably be a good idea to replace the full path in the settings with a relative path.

Sorry for the length of this, my first ever, post but I couldn't think of a way to make it any more concise. Anyway I hope this is of some use and good luck with the rest of the book.
 
Old March 20th, 2006, 09:15 AM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the detailed explanation. The logic of a separate .mdf for debug makes sense. BUT I sure wish it had been explained in the book. I wasted a day trying to find where I had messed up. I never considered a debug copy. For tutorial purposes, I suppose the simplest way it to use debug until the exercise proccesses as expected then build and run to change the project .mdf. I haven't tried this yet, but sounds good ;)

Sturdy

 
Old March 20th, 2006, 09:24 AM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Humble:

Thanks for the solution.

It does not work here.

Tried to do all of your above suggestions.

Created a database with the SQL Server Management and tried to link to that one, seems that Visual C# Express Edition makes a copy of the database and I am right at squeare one.
The fault is probably mine and not yours.

Was using Java and Mysql and Derby from Apache before,
never any trouble, but I really would like to get C# and the Sql Server to work - were is Wrox ? I sent an error report on this, but no reply.

 
Old March 20th, 2006, 09:27 AM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sturdy:

Did this work for you ?
I both tried to run it as 'start without debugging' and directly from the
/bin/debug directory.

could you fill me in ? if u have the time ?

frustrated here ....

- I

 
Old March 20th, 2006, 01:04 PM
Registered User
 
Join Date: Mar 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi inkimar,

Yes, it works for me too but but as Humble pointed out the DB that is updated is a copy in the debug folder. I confirmed my VB update by copying the debug DB to the project folder and then viewed the Show Table Data for Book and Person in Database Explorer. My data was there. I guess the logic is to make a 'working' copy for debug to avoid scrambling the original DB. Seems to work okay if you know what to expect. I have not had time to try C# again but it should operate the same as VB.

Sturdy

 
Old March 20th, 2006, 01:52 PM
Authorized User
 
Join Date: Mar 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Sturdy!

Will get back to you, try this out tomorrow.
Time is getting 1900, time to go home.

regards, i

 
Old March 20th, 2006, 02:21 PM
Authorized User
 
Join Date: Dec 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Inkimar

Keep us updated as to progress and I'll provide what help I can but I'm a beginner (wouldn't be using the book if I wasn't I guess)and only doing this as a 'retirement' hobby. Means I have time to try things though.

Glad to be of help Sturdy.

For the future I think I should say that Microsoft are looking at the problem and so I guess they recognise that the default behaviour is a problem. What annoys me is that even the Microsoft documentation does not mention the way it works.

I'll try to keep in touch with the forums on a daily basis.

Regards

Humble Weeble





Similar Threads
Thread Thread Starter Forum Replies Last Post
master-detail hhpatek ADO.NET 0 April 3rd, 2008 02:53 PM
Master Detail prasanta2expert Access VBA 1 October 1st, 2007 06:37 AM
master/detail beeyule Dreamweaver (all versions) 1 January 18th, 2005 02:59 AM
Detail-Master updating problem CW Classic ASP Databases 2 October 22nd, 2003 10:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.