Tutorials » AspNet tutorials »

Core classes in ADO.NET

This chapter introduces various classes provided by ADO.NET to perform various database operations.

Classes for communicating with database

The Connection, Command, DataReader, and DataAdapter objects are the core elements of the ADO.NET provider model.

ObjectDescriptionSqlClient ObjectsOleDb Objects
ConnectionEstablishes a connection to a specific data source.SqlConnectionOleDbConnection
CommandExecutes a command against a data source.SqlCommandOleDbCommand
DataReaderReads a forward-only, read-only stream of data from a data source.SqlDataReaderOleDbDataReader
DataAdapterPopulates a DataSet and resolves updates with the data source.SqlDataAdapterOleDbDataAdapter

Each provider may have classes equivalent to above objects. The name of the classes vary slightly to represent the provider type appropriately.

Depending on the type of database you work on, you will have to choose either OleDb or SqlClient (or, some other provider) objects. Since all our samples use MS Access database, we will be using OleDb objects in all the samples. If you like to use SqlServer, you just need to replace the OleDb objects with the equivalent SqlClient objects.

Classes for holding and manipulating data

The following are the main classes used to hold data in Ado.NET:

  • DataSet
  • DataTable
  • DataRow

A DataSet is an in-memory representation of the database.

DataSet contains one or more DataTables (and more like Views etc...)

A DataTable represents a database table

DataTable contains one or more DataRows (and more...)

A DataRow represents a record in a database table.

DataRow is a collection of all fields in a record.

We can use the DataAdapter or DataReader to populate data in DataSet. Once we populate data from database, we can loop through all Tables in the DataSet and through each record in each Table.

On the first look, this may look bit confusing, but once you understand the concept and get familiar with the Ado.NET classes, you will appreciate the power and flexibility of Ado.NET.

Next Chapter: Basic Database operations using ADO.NET
Previous Chapter: Introduction to ADO.NET
More Chapters: ASP.NET Tutorials
More Tutorials: Tutorial Index

Top Contributors
    Last 7 Daysmore...

    Awards & Gifts

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India