Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > BOOK: Beginning C# 2005 Databases
|
BOOK: Beginning C# 2005 Databases
This is the forum to discuss the Wrox book Beginning C# 2005 Databases by Karli Watson; ISBN: 9780470044063
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 2005 Databases 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 July 7th, 2009, 03:06 AM
mms mms is offline
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Question of Ex0403- Multi-Table Modification

Hi,

I have a question of Ex0403.
When I add a new record, Here prompts the mistake.
whether "tableChanges != tableDeletes" should be "tableDeletes != null"?

Thanks!

In Page 136:
15. Modify the event handler for the Save Data button as follows:

Code:
private void sourceBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
    this.Validate();
    this.sourceBindingSource.EndEdit();
    this.storyBindingSource.EndEdit();
    
    // Save added / edited parent rows
    FolktaleDBDataSet.SourceDataTable tableChanges =
        folktaleDBDataSet.Source.GetChanges(
        DataRowState.Added | DataRowState.Modified)
        as FolktaleDBDataSet.SourceDataTable;
    if (tableChanges != null)
    {
        sourceTableAdapter.Update(tableChanges);
    }
 
    // Save child row modifications
    characterStoryTableAdapter.Update(folktaleDBDataSet.CharacterStory);
    storyLocationTableAdapter.Update(folktaleDBDataSet.StoryLocation);
    storyTableAdapter.Update(folktaleDBDataSet.Story);
 
    // Save deleted parent rows
    FolktaleDBDataSet.SourceDataTable tableDeletes =
        folktaleDBDataSet.Source.GetChanges(DataRowState.Deleted)
        as FolktaleDBDataSet.SourceDataTable;
    if (tableChanges != tableDeletes)
    {
        sourceTableAdapter.Update(tableDeletes);
    }
 
    // Accept changes
    folktaleDBDataSet.AcceptChanges();
    }

Last edited by mms; July 7th, 2009 at 03:09 AM..
 
Old July 21st, 2009, 10:00 PM
mms mms is offline
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default P220:Modifying Database Data

Page 219-220:

Code:
// Parent table additions and modifications.
DataTable dataTableAChanges1 = dataTableA.GetChanges(
    DataRowState.Added | DataRowState.Modified)
if (dataTableAChanges1 != null)
{
    adapterA.Update(dataTableAChanges1);
}
// Child table changes.
adapterB.Update(dataTableB);
 
// Parent table deletions.
DataTable dataTableAChanges2 = dataTableA.GetChanges(DataRowState.Deleted)
if (dataTableAChanges2 != null)
{
    adapterA.Update(dataTableAChanges2);
}
// Accept changes in parent table.
dataTableA.AcceptChanges();
Codes for these two contradictory.
I think that is the code "dataTableAChanges2 != null", code "tableChanges != tableDeletes" is wrong.

My explanation is correct? thanks!

Last edited by mms; July 21st, 2009 at 10:09 PM..
 
Old July 23rd, 2009, 07:24 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

mms:
In my opinion, the difference between pages 136 and 219-220 is the difference in database structure. The DB structure on page 136 is Hierarchial in structure while the DB structure on pages 219-220 is Relational. The author maintains the process of modification or modifying the two different structures is the same:
  • Step 1: Add or Update changes to the Parent Table, but no deletes;
  • Step 2: Add, Update and Delete modifications to the Child Table;
  • Step 3: Make Deletions to the Parent Table;
  • Step 4: Then commit changes/updates to the Database.
The author notes on page 131 in Hierarchial Structure DB for modifications steps 2 and 3 are expanded and to proceed with caution. Due to the complex levels of the structure, one must save the all changes and deletions of the children, hence the if-statement:
  • if (tableChanges != tableDeletes)
Hope this helps
__________________
Disclaimer: The above comments are solely the opinion of one person and not to be construed as a directive or an incentive to commit fraudulent acts.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi table DataGrid melvik C# 1 October 6th, 2007 04:30 PM
question regarding multi-column.html of chapter 2 mikeni1225 BOOK: CSS Instant Results 9 July 2nd, 2007 06:24 PM
Ordering price when multi-currency table jwhite68 SQL Server 2000 3 June 13th, 2007 08:46 AM
Unknown table 'char_main' in MULTI DELETE uniacid Beginning PHP 9 December 11th, 2006 04:59 PM
multi-multi-multiple Insert with subquery??? jmjyiannis SQL Server 2000 1 May 5th, 2006 02:20 PM





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