«

»

Jul 19

Data Adapters in ADO.Net

CSharpDataSmData Adapters are the objects in ADO.Net that allow us to communicate and exchange data between a data source and a dataset.  With them, we are able to retrieve data from and write data to a database (actually any type of data repository).

The type of database you are connecting to informs you as to which data adapter you should utilize.

  • OleDBDataAdatper is a general adapter suitable for any OleDB data source
  • SqlDataAdapter is specifically for connecting to a SQL Server database
  • ODBCDataAdapter is used to connect to general ODBC data sources
  • OracleDataAdapter is specifically for connecting to an Oracle database

While the DataAdapter communicates with the database, it requires other objects to support it.

A Connection Object defines, opens and maintains or closes the connection to the database.  The connection can be assigned to one or more adapters.  The Connection object is where you configure your connection parameters to the database.

Command Objects execute actions on the dataset.  These include Select, Insert, Update and Delete.

To retrieve data from a data set, you call the ‘Fill’ method on the data adapter.  To write data, you use the ‘Update’ method.

If your task needs only to grab data and load it once (not to ever write back) you can use a Data Reader.  These Read Only, Forward Only objects load data from the dataset once and store it in collections you can access.  The advantage of this is that it only hits the database once, grabs data and lets go of the database.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>