0
5.5kviews
Explain ADO.NET with an example

Mumbai University > Information Technology > Sem 4 > Web Programming

Marks: 5M

Year: May 2014

1 Answer
0
418views
  • ADO.NET provides an API for accessing database systems according to the programs.
  • ADO.NET was created for the .NET framework and it can be said that they are the next generation of Active Data Objects (ADO).
  • The .NET framework contains several namespaces and classes, which are developed to database access.
  • Microsoft has created namespaces that are optimized for working with different data providers, i.e. different types of databases.
  • ADO.NET allows us to interact with different types of data sources and different types of databases.
  • Since different data sources expose different protocols, we need a way to communicate with the right data source using the right protocol.
  • Following are the different protocols provided by ADO.NET for working with the data source;
    • ODBC Data Provider
    • OleDb Data Provider
    • Oracle Data Provider
    • SQL Data Provider
    • Borland Data Provider
  • ADO.NET includes many objects to work with database. The primary objects are
    • Connection Object: To interact with database, one must have a connection to it. The connection objects helps to identify database server, database name, user name and password.
    • Command Object: This is used to specify action needs to perform on database. A command object must use Connection object to figure out which database to communicate with.
    • DataReader Object: This object is used to obtain results of a SELECT statement form a command object.
    • DataSet Object: This is used to manipulate a data obtained from the results. This manages data in memory and supports disconnected operations on data.
    • DataAdapter Object: It contains a reference to connection object and opens and closes the connection automatically. It also contains command object references for Insert, Delete and Update operations on data. DataAdapter should be defined for each table in dataset.

Example:

Dim con as OleDbConnection
Dim cmd as OleDbCommand
Dim dtr as OleDbDataReader
con= New OleDbConnection(“PROVIDER=Microsoft.Jet.OLEDB4.0:DATA Source=c:\Employees.mdb”)
con.Open();
cmd=New OleDbCommand(“Select FirstName from Employees”, con)
dtr=cmd.ExecuteReader()
While dtr.Read()
    Response.Write(dtr(“firstname”))
End While
dtr.close()
con.close()
Please log in to add an answer.