ADO.NET tutorial for beginners - Part 16 Dataset rejectchanges and dataset acceptchanges methods

Database, Information Technology

ADO.NET tutorial for beginners

61 Lessons

Part 16 Dataset rejectchanges and dataset acceptchanges methods

This is continuation to Part 15. Please watch Part 15, before proceeding.

To understand AcceptChanges() and RejectChanges() methods better, we need to understand Row States and Row Versions.

Every DataRow that is present in DataTable of a DataSet has RowState property. Please check the following MSDN link, for different values of RowState property and their description. Different DataRowVersion enumeration values and their description is also present.

HasVersion() method can be used to check if a row has got a specific DataRowVersion.

When we call DataAdapter.Fill() method, data is loaded into the DataSet and the RowState of all the rows will be Unchanged. When we edit a row the row state becomes Modified. If we delete a row, the row state becomes Deleted. At this point with in the DataSet, we have got Unchanged, Deleted and Modified rows. If we then invoke, DataAdapter.Update() method, based on the RowState, respective INSERT, UPDATE and DELETE commands are executed against the underlying database table and AcceptChanges() is called automatically.

When AcceptChanges() is invoked RowState property of each DataRow changes. Added and Modified rows become Unchanged, and Deleted rows are removed.

When RejectChanges() is invoked RowState property of each DataRow changes. Added rows are removed. Modified and Deleted rows becomes Unchanged.

Both AcceptChanges() and RejectChanges() methods can be invoked at the following levels
1. At the DataSet level – When invoked at the DataSet level, they get called automatically on each DataTable with in the DataSet, and on each DataRow within each DataTable.
2. At the DataTable level – When invoked at the DataTable level, they get called automatically on each DataRow within each DataTable.
3. At the DataRow level – Gets called only for the row, on which it is invoked.

Text version of the video


All ADO .NET Text Articles

All ADO .NET Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

    .Net .net sqldatareader multiple result sets Access Added ado net sql transaction example cache dataset transaction c# transaction example tutorial Advantages asp net dataset delete row asp net dataset update to database bind dataset multiple tables c# data access tutorial c# database connection c# database connection with sql server c# sqlbulkcopy connect to sql server database connect to sql server tutorial database application datareader multiple results dataset insert row dataset multiple tables dataset update row fill dataset with multiple tables gridview dataset multiple tables sql connection example c# sqlbulkcopy datatable transaction example web application database benefits bulk copy class c# C# c# .net data access tutorial c# bank transaction c# bulkcopy datatable c# data access tutorial c# data provider c# database transaction rollback c# datagridview dataset multiple tables c# datareader multiple tables c# dataset 2 tables c# dataset insert into database c# dataset insert update delete c# dataset multiple tables stored procedure c# dataset two tables c# dataset without database c# datatable rowstate deleted c# disconnected dataset c# load data from database c# sql transaction try catch c# sqlbulkcopy batch c# sqlbulkcopy class c# sqlbulkcopy database c# sqlbulkcopy datatable example c# sqlbulkcopy example c# sqlbulkcopy xml data c# sqlcommandbuilder update c# sqlconnection example c# sqlconnection sqlcommand c# sqldatareader example c# sqldatareader sample code c# transaction best practices c# transaction commit rollback c# transaction exception c# transaction rollback exception caching dataset calling can we store multiple tables in datareader class command commandbuilder update command c# configuration file connection connection string connection string sql authentication connectionstring windows authentication c# ConnectionStrings Data data access in dot net data access techniques in c# DataAdapter database datareader c# multiple result sets DataRowVersion dataset dataset crud example dataset disconnected architecture Deleted Detached difference between typed and untyped dataset difference between typed and untyped dataset in differences disconnected disconnected data access disconnected database in c# dot net dot net data provider dotnet example ExecuteNonQuery ExecuteReader ExecuteScalar executing gridview using dataset in gridview with dataset c# haschanges injection insert data using sqlbulkcopy in c# insert xml data into sql table using c# interview introduction to data access in .net load xml data into sql server methods Modified moving data from one table to another in sql multiple tables in datareader c# NextResult() method not working Object output parameters parameterized queries prevention primary key questions rejectchanges retrieve connection string from app.config c# retrieving multiple result sets using nextresult c# row RowState sql sql connection SQL Injection sql injection attack mechanisms and prevention techniques sql injection demo sql injection detection and prevention techniques sql injection for dummies sql injection forms sql injection get request sql injection hacking basics tutorial sql injection how to sql injection in search box sql injection in search field sql injection in search query sql injection lessons sql injection on website sql injection post request sql injection prevention sql injection prevention best practices sql injection prevention cheat sheet sql injection prevention in sql injection prevention methods sql injection prevention system sql injection prevention techniques sql injection prevention tutorial sql injection queries sql injection real life example sql injection real world example sql injection simple explanation sqlbulkcopy c# sqlbulkcopy example sqlbulkcopy table to table SqlCommand SqlCommandBuilder sqlcommandbuilder update c# sqlcommandbuilder update command c# sqlconnection sqldataadapter sqldataadapter c# example select SqlDataReader sqldatareader example sqldatareader loop through columns sqldatareader loop through fields sqldatareader loop through rows sqldatareader multiple tables sqldatareader read all columns sqldatareader read all rows sqldatareader read column value sqldatareader read example sqldatareader read to end sqldatareader read while states stored procedure stored procedures Strongly transaction in c# with example transaction in using c# transaction in transaction in c# transactions in tutorial two or more result sets typed typed versus untyped datasets typed vs untyped dataset Unchanged untyped Update use of using keyword in c# versions Weakly web application Web.Config what is data provider in c# windows application app config connection string