0% found this document useful (0 votes)
230 views

Ado.net

ADO.NET is a collection of classes that exposes data access services for the .NET framework. It provides a rich set of components for creating distributed data sharing applications and contains libraries to interact with data sources. It has advantages over ADO like faster performance and optimized interaction with SQL Server. The core classes include DataSet for storing data in memory disconnected from the data source, DataAdapter for synchronizing data between a DataSet and database, and DataReader for read-only forward scrolling of records from a data source.

Uploaded by

Example Ex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views

Ado.net

ADO.NET is a collection of classes that exposes data access services for the .NET framework. It provides a rich set of components for creating distributed data sharing applications and contains libraries to interact with data sources. It has advantages over ADO like faster performance and optimized interaction with SQL Server. The core classes include DataSet for storing data in memory disconnected from the data source, DataAdapter for synchronizing data between a DataSet and database, and DataReader for read-only forward scrolling of records from a data source.

Uploaded by

Example Ex
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to ADO.

NET

ADO.NET is a collection of classes that


exposes data access services for the .NET
framework. It provides a rich set of
components for creating distributed data
sharing applications. It contains a set of
libraries that helps the user to interact
with the data sources.
Advantages of ADO.NET
1) The performance of ADO.NET is much faster
than ADO
2) It contains SQL Server Data Provider which is
optimized for interaction with SQL Server
3) It provides a good support for XML data
4) It provides disconnected operation model
through the use of Datasets
5) It has rich object model providing class
inheritance and interface implementation
The table containing the list of
providers is as shown below:
Advantages of using Data Providers in
ADO.NET
1) It provides high performance of client-server access over RDBMS
2) It contains trigger providing powerful means for maintaining
business rules at database level
3) It provides referential integrity that supports primary/foreign
key definition
4) It provides data access through table or server side control
5) It is easy to convert the .NET framework to other database
engines
6) It contains full server based transaction to eliminate database
corruption
7) It has database security functionality and encryption support
Architecture of ADO.NET
The DataSet Class
 The dataset represents a subset of the
database. It does not have a continuous
connection to the database. To update
the database a reconnection is required.
The DataSet contains DataTable objects
and DataRelation objects. The
DataRelation objects represent the
relationship between two tables.
Following table shows some important
properties of the DataSet class:
The following table shows some
important methods of the DataSet
class:
The DataTable Class
The DataTable class represents the
tables in the database. It has the
following important properties;
most of these properties are read
only properties except the
PrimaryKey property:
The DataRow Class
The DataRow object represents a row in a table.
It has the following important properties:
The following table shows some important
methods of the DataRow class:
The DataAdapter Object

The DataAdapter object acts as a


mediator between the DataSet
object and the database. This
helps the Dataset to contain data
from multiple databases or other
data source.
The DataReader Object

 The DataReader object is an alternative to


the DataSet and DataAdapter combination.
This object provides a connection oriented
access to the data records in the database.
These objects are suitable for read-only
access, such as populating a list and then
breaking the connection.
DbCommand and DbConnection
Objects
 The DbConnection object represents a
connection to the data source. The
connection could be shared among
different command objects.
 The DbCommand object represents the
command or a stored procedure sent to
the database from retrieving or
manipulating data.
 <head runat="server">
 <title> Untitled Page </title>
 </head>
 <body>
 <form id="form1" runat="server"> <div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView> </div>
 </form>
 </body>
 </html>
 namespace createdatabase
 {
 public partial class _Default : System.Web.UI.Page
 {
 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack) { DataSet ds = CreateDataSet();
GridView1.DataSource = ds.Tables["Student"];
GridView1.DataBind();
 }
 }
 private DataSet CreateDataSet()
 {
 //creating a DataSet object for tables DataSet dataset = new
DataSet();
 // creating the student table DataTable Students =
CreateStudentTable();
 dataset.Tables.Add(Students);
 return dataset;
 }
 private DataTable CreateStudentTable()
 {
 DataTable Students = new DataTable("Student");
 // adding columns
 AddNewColumn(Students, "System.Int32", "StudentID");
AddNewColumn(Students,"System.String","StudentName");
AddNewColumn(Students, "System.String", "StudentCity");
 // adding rows AddNewRow
 (Students, 1, "M H Kabir", "Kolkata");
AddNewRow(Students, 1, "Shreya Sharma", "Delhi");
AddNewRow(Students, 1, "Rini Mukherjee", "Hyderabad");
AddNewRow(Students, 1, "Sunil Dubey", "Bikaner");
AddNewRow(Students, 1, "Rajat Mishra", "Patna");
 return Students;
 }
 private void AddNewColumn(DataTable table, string
columnType, string columnName)
 {
 DataColumn column = table.Columns.Add(columnName,
Type.GetType(columnType));
 }

 //adding data into the table private void


AddNewRow(DataTable table, int id, string name, string
city)
 {
 DataRow newrow = table.NewRow();
newrow["StudentID"] = id;
 newrow["StudentName"] = name;
 newrow["StudentCity"] = city; table.Rows.Add(newrow);
 }
 }
 }

You might also like