Page 92 - DCAP312_WEB_TECHNOLOGIES_II
P. 92
Web Technologies-II
Notes There are two central components of ADO.NET classes:
• the DataSet, and
• the .NET Framework Data Provider.
Data Provider is a set of components including the:
• Connection object(SqlConnection, OleDbConnection, OdbcConnection, OracleConnection),
• Command object(SqlCommand, OleDbCommand, OdbcCommand, OracleCommand),
• DataReader object (SqlDataReader, OleDbDataReader,OdbcDataReader,
OracleDataReader),and DataAdapter object(SqlDataAdapter, OleDbDataAdapter,
OdbcDataAdapter, OracleDataAdapter).
DataSet object represents a disconnected cache of data which is made up of DataTables and
DataRelations that represent the result of the command.
5.1.2 The ADO.NET Object Model
The ADO.NET object model is as following (See Figure 5.1):
Figure 5.1: ADO.NET Object Model
ADO.NET
Data Provider
Data Consumers
Data Adapter Data Set Win Form
Web Form
Connection Command
Other
Data Reader
1. Connection to an ADO.NET Database
Before working with a database, you have to add (here) the OleDb .NET Data Provider namespace,
by placing the following at the start of your code module:
using System.Data.OleDb;
Similarly for the SqlClient .NET Data Provider namespace:
using System.Data.SqlClient;
The using statement should be positioned first in your code.
Now we have to declare a connection string pointing to a MS Access
database “PersonDatabase.mdb”.
publicstringconString=@“Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=..\..\PersonDatabase.mdb”;
86 LOVELY PROFESSIONAL UNIVERSITY