adonet
  1. adonet-ado-vs-adonet

ADO vs ADO.NET - (ADO.NET Examples)

ADO (ActiveX Data Objects) and ADO.NET (ActiveX Data Objects .NET) are both Microsoft technologies used for data access. ADO was introduced in the mid-1990s, while ADO.NET was introduced in 2002 as a part of the .NET framework. Though both technologies serve the same purpose, there are several differences between them.

Syntax

ADO and ADO.NET are both used for data access in applications. However, the syntax used for data access is different in each technology.

In ADO, data access is typically done through a recordset object:

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;"
cn.Open
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Customers", cn

In ADO.NET, data access is done through a dataset object, which can be filled with data using a data adapter:

Dim cn As New SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;")
Dim da As New SqlDataAdapter("SELECT * FROM Customers", cn)
Dim ds As New DataSet
da.Fill(ds)

Example

Here's an example of how to retrieve a single record from a MS Access database using ADO:

Dim cn As New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"
Dim rs As New ADODB.Recordset
rs.Open "SELECT * FROM Customers WHERE CustomerID = 'ALFKI'", cn
MsgBox "Company Name is " & rs("CompanyName").Value

Here's an example of how to retrieve a single record from a MS SQL Server database using ADO.NET:

Dim cn As New SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;")
Dim cmd As New SqlCommand("SELECT * FROM Customers WHERE CustomerID = @CustomerID", cn)
cmd.Parameters.AddWithValue("@CustomerID", "ALFKI")
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
    dr.Read()
    MsgBox "Company Name is " & dr("CompanyName").ToString()
End If

Output

The output of both examples should be a message box that displays the company name of the specified customer.

Explanation

ADO and ADO.NET serve the same purpose, but there are several differences between the two technologies:

  • ADO was designed for use with COM, while ADO.NET was designed for use with the .NET framework.
  • ADO uses a recordset object, while ADO.NET uses a dataset object.
  • ADO uses a client-side cursor model, while ADO.NET uses a server-side cursor model.
  • ADO.NET provides better support for disconnected data access.

Use

Both ADO and ADO.NET can be used for data access in applications. However, ADO is an older technology that is no longer being actively developed, while ADO.NET is the recommended method for data access in .NET applications.

Important Points

  • ADO and ADO.NET are both Microsoft technologies used for data access.
  • ADO uses a recordset object, while ADO.NET uses a dataset object.
  • ADO provides better support for client-side cursor models, while ADO.NET provides better support for server-side cursor models.
  • ADO.NET is the recommended method for data access in .NET applications.

Summary

In this page, we discussed the differences between ADO and ADO.NET. We covered the syntax, example, output, explanation, use, and important points of each technology. While ADO is an older technology that is still in use in some applications, ADO.NET is the recommended method for data access in .NET applications.

Published on: