
2. Dataset
Understanding Datasets in ADO.NET
Overview
ADO.NET presents a flexible and efficient way to access data in a database. It provides two key programming environments: Connected and Disconnected. Each mode is suitable for different scenarios and has a set of dedicated classes to handle data operations.
Connected Mode
Definition
The connected mode in ADO.NET provides forward-only, read-only access to data from a data source. This mode allows the execution of commands against the data source directly.
Key Classes in Connected Mode
Key classes used in connected mode include:
Connection
: Establishes a connection to a specific data source.
Command
: Represents a SQL statement to execute against a data source.
DataReader
: Reads a forward-only stream of rows from a data source.
Transaction
: Represents a SQL transaction to be made at a data source.
ParameterCollection
: Represents a collection of allParameter
objects.
Parameter
: Represents a parameter to aCommand
object.
Use Case
Connected mode is most efficient when the data is fetched from the database infrequently (e.g., once a day).
Disconnected Mode
Definition
The disconnected mode allows data retrieved from the data source to be manipulated offline and later reconciled with the data source. This mode is beneficial when you need to work with the data without maintaining a constant connection to the data source.
Key Classes in Disconnected Mode
Key classes used in disconnected mode include:
DataSet
: Represents an in-memory cache of data.
DataTable
: Represents one table of in-memory data.
DataColumn
: Represents the schema of a column in aDataTable
.
DataRow
: Represents a row of data in aDataTable
.
Constraint
: Used to enforce rules for the data in aDataTable
.
DataRelationship
: Represents a relationship between twoDataTable
objects.
DataView
: Represents a databindable, customized view of aDataTable
.
Use Case
Disconnected mode is most efficient when data is fetched from the database frequently.
DataAdapter Class
The DataAdapter
class in ADO.NET bridges the gap between the connected and disconnected classes. It's an abstraction of the connected classes that simplifies filling the disconnected DataSet
or DataTable
classes with data from the data source and updating the data source to reflect any changes made to the disconnected data.
Conclusion
Understanding the different modes in ADO.NET and their respective classes is crucial for efficient database operations. It's important to note that the choice between connected and disconnected modes depends largely on the specific requirements of your application.
Reference
The content in this document is based on the original notes provided in Azerbaijani. For further details, you can refer to the original document using the following link:
Original Note - Azerbaijani Version