ADO.Net
ADO.Net
NET
ADO.NET is a set of classes to interact with data sources such as
databases (data sources). ADO is the acronym for ActiveX Data Objects. It
allows us to interact with the different data sources like MySql,
Oracle ,SQL Server etc. (databases). It has classes and methods to
retrieve and manipulate data.
The following are a few of the .NET applications that use ADO.NET to
connect to a database, execute commands and retrieve data from the
database.
ASP.NET Web Applications
Console Applications
Windows Applications.
Connection Architectures
There are the following two types of connection architectures:
1. Connected architecture: The application remains connected with
the database throughout the processing. Eg Connection, Command,
DataReader, DataAdapter etc.
ADO.NET Architecture:
In this diagram, we can see that there are various types of
applications (Web Application, Console Application, Windows Application
and so on) that use ADO.NET to connect to databases (SQL Server, Oracle,
OleDb, ODBC and so on).
2. Command Class
The Command class provides methods for storing and executing
SQL statements and Stored Procedures. The following are the various
commands that are executed by the Command Class. SELECT, INSERT,
UPDATE, and DELETE Database queries are used to obtain, add, and
remove data.
ExecuteReader: Returns data to the client as rows. This would
typically be an SQL select statement or a Stored Procedure that
contains one or more select statements. This method returns a
DataReader object that can be used to fill a DataTable object or used
directly for printing reports and so forth.
ExecuteNonQuery: Executes a command that changes the data in
the database, such as an update, delete, or insert statement, or a
Stored Procedure that contains one or more of these statements. This
method returns an integer that is the number of rows affected by the
query.
ExecuteScalar: This method only returns a single value. This kind of
query returns a count of rows or a calculated value.
ExecuteXMLReader: (SqlClient classes only) Obtains data from an
SQL Server 2000 database using an XML stream. Returns an XML
Reader object.
3. DataReader Class
The DataReader is used to retrieve data. It is used in conjunction
with the Command class to execute an SQL Select statement and then
access the returned rows.
4. DataAdapter Class
The DataAdapter is used to connect DataSets to databases. The
DataAdapter is most useful when using data-bound controls in Windows
Forms, but it can also be used to provide an easy way to manage the
connection between your application and the underlying database tables,
views and Stored Procedures.
5. DataSet Class
The DataSet is the heart of ADO.NET. The DataSet is essentially a
collection of DataTable objects. In turn each object contains a collection of
DataColumn and DataRow objects. The DataSet also contains a Relations
collection that can be used to define relations among Data Table Objects.
values(1,’Ram’,10000)”, cn);
cmd.ExecuteNonQuery();
cn.Close();
using System;
using System.Data;
using System.Windows.Forms;
namespace OracleConnection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}