Wrox Programmer Forums
|
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 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 January 6th, 2017, 07:44 AM
Registered User
 
Join Date: Jan 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 9 update and delete records using dataadapter

Using codelab p387
we have prepopulated the da with update and delete commands via:
da.UpdateCommand = update;
da.DeleteCommand = delete;


what is the effect of the below. We have made modifications to the DS including updating the first row (ds.Tables[0].Rows[0]["FirstName"] = "Jack";) and deleting the second row(ds.Tables[0].Rows[1].Delete();).
What are we updating to the database via this command. i understand we are running update and delete sql statements but what are they ?
da.Update(ds.Tables[0]);
 
Old January 6th, 2017, 07:48 AM
Registered User
 
Join Date: Jan 2017
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default potential response

is the effect of the da.Update(ds.Tables[0]); only to update the first record to Jack Johnson and delete the second record????????? what about all the other records in the DataSet?
 
Old January 7th, 2017, 02:01 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

See my reply to your earlier thread. The Update method uses the insert, updated, and delete command objects to update any records that are out of sync with the values in the database. It adds new records, updates modified ones, and removes deleted records.

Any records that have not been changed in the data set are not touched in the database to reduce the amount of data that must be transmitted back to the database server.

Again, reply if that 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!)
 
Old January 7th, 2017, 02:10 PM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry, I missed this part:

Quote:
i understand we are running update and delete sql statements but what are they ?
The short answer is that the command objects (like the insert object) tell the data adapter how to insert, update, and delete data in the database.

This example sets the command text for the objects. For example, the insert command's text is:

Code:
INSERT INTO Students (FirstName, LastName)
VALUES (@FirstName, @LastName)


Then the code adds parameters that define the fields @FirstName and @LastName.

When you update the database, the command object basically loops through the new records, replaces @FirstName and @LastName with the record's values in the INSERT statement, and executes it. After the replacements, the command strings are something that the database can understand so it takes the necessary action, in this case inserting the records.

The update and delete objects (if they are present) do something similar.

You can also use command builders to make the commands slightly more automatically. See https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx for more on that.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Add/Update/Delete Database records MANUALLY jn148 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 December 14th, 2008 10:18 AM
update dataadapter karenai Visual Basic 2005 Basics 0 February 9th, 2008 10:46 PM
Datagrid.update() and DataAdapter.Update aarunlal ASP.NET 2.0 Professional 2 February 23rd, 2006 11:41 PM
Inserting records into DB using DataAdapter favor ADO.NET 4 June 16th, 2005 02:29 AM
How to Add/Delete/Update multiple records in DB? mmwaikar ADO.NET 1 September 20th, 2003 11:41 AM





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