Check out and contribute to CodePedia, the wiki for developers.

How do I save the changes, made in the dataset, to the database?

We update the dataset and table by calling the Update method of the data adapter. This saves the changes in the local repository of data: dataset. To save the changed rows and tables to the physical database, we call the AcceptChanges() method of the DataSet class.

C# Version
dataAdapter.Update(ds, "student");
ds.AcceptChanges();


VB.Net Version
da.Update(ds, "student")
ds.AcceptChanges()


Here ‘da’ is the reference to the data adapter object, ‘ds’ is the reference to the dataset, and ‘student’ is the name of table we want to update.

Note: For the next four FAQs, we will demonstrate sample applications. For these applications to work, you need following database and tables created in your database server. A database named ‘ProgrammersHeaven’ is created. It has a table named ‘Article’. The fields of the table ‘Article’ are

Field NameTypeDescription
artId (Primary Key)IntegerThe unique identity of article
TitleStringThe title of the article
TopicStringTopic or Series name of the article like ‘Multithreading in Java’ or ‘C# School’
authorId (Foreign Key)IntegerUnique identity of author
LinesIntegerNo. of lines in the article
dateOfPublishingDateDate of publishing of the article
The ‘ProgrammersHeaven’ database also contains a table named ‘Author’ with the following fields

Field NameTypeDescription
authorId (Primary Key)IntegerThe unique identity of author
nameStringName of author


Back
 

Other Views

corner
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.