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 Name | Type | Description |
|---|
| artId (Primary Key) | Integer | The unique identity of article |
| Title | String | The title of the article |
| Topic | String | Topic or Series name of the article like ‘Multithreading in Java’ or ‘C# School’ |
| authorId (Foreign Key) | Integer | Unique identity of author |
| Lines | Integer | No. of lines in the article |
| dateOfPublishing | Date | Date of publishing of the article |
The ‘ProgrammersHeaven’ database also contains a table named ‘Author’ with the following fields
| Field Name | Type | Description |
|---|
| authorId (Primary Key) | Integer | The unique identity of author |
| name | String | Name of author |
Back