Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2012/5.0 > BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C#
This is the forum to discuss the Wrox book MCSD Certification Toolkit (Exam 70-483): Programming in C# by Tiberiu Covaci, Rod Stephens, Vincent Varallo, Gerry O'Brien; ISBN: 978-1-118-61209-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: MCSD Certification Toolkit (Exam 70-483): Programming in C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 6th, 2017, 06:33 AM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 use a dataadapter to add a record

Codelab on p385 and p386 is below.
The data from the person table is extracted into a DataSet obj via the Fill command. DS at this point would contain all the records of the person table
da.Fill(ds, "Person");

We then add a new row to the DS.
DataRow newRow = ds.Tables[0].NewRow();
newRow["FirstName"] = "Jack";
newRow["Surname"] = "Johnson";
ds.Tables[0].Rows.Add(newRow);

My question is a confirmation. i assume ds.tables[0].Rows.Add(newRow) must clear the contents of the DS and add one row (jane doe). As the update command da.update(ds.TAbles[0]) inserts all of the rows in DS to the database.
CAn you please confirm this or explain otherwise. i am failing to understand how the DS suddenly contains all the data and then after those adding row statements it is reduced to a single record.
Reply With Quote
  #2 (permalink)  
Old January 7th, 2017, 12:58 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,153, Level: 23
Points: 3,153, Level: 23 Points: 3,153, Level: 23 Points: 3,153, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 643
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Ksackel. Sorry for the slow reply. I was hoping the author of that chapter would respond (so I would have to think ).

The short answer is no, when you add a new record to it the DataSet still holds all of the other records.

Here's the longish explanation.

When you add a new record to a DataSet, the old records are still in it. Each rows has a state that records whether it is the original data loaded from the database, modified, added, or deleted.

You can see the records' statuses by looking at the row's State property. For example:

ds.Tables[0].Rows[5].RowState

When you add the new record, it is marked as new.

When you use Update to save changes to the database, the data adapter copies any changes (adds, deletes, or changes) back to the database.

It doesn't touch the unmodified records because they haven't changed. That can save a ton of time. For example, suppose you have 5,000 records but you only changed 1.

It then changes the state of all of the modified records to Unchanged to show that the data set is up to date with the database.

I hope that helps. Reply if it doesn't make sense.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Last Record and Add new keyed record causualuser Access VBA 3 February 9th, 2009 07:24 AM
how to add new record as first record in dataset hunzian78@yahoo.com ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 05:23 AM
Help with Add record topshed Classic ASP Basics 6 February 7th, 2006 01:59 AM
Add row using dataadapter.update JelfMaria VS.NET 2002/2003 0 June 29th, 2005 09:06 AM
Cannot add new record geolando Access 0 June 27th, 2005 06:23 PM



All times are GMT -4. The time now is 04:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.