Page 93 - DCAP312_WEB_TECHNOLOGIES_II
P. 93
Unit 5: Database Access
The database should be in the specified path, otherwise you should change the path accordingly. Notes
The next step is to create an OleDbConnection object. We pass then the connection string to this
OleDbConnection object.
You can code now to create a new ADO.NET Connection object in order to connect to an OLE
DB provider database.
OleDbConnection con = new OleDbConnection(conString);
You can also explicitly reference declared objects if you don?t mind typing a lot.
System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.
OleDbConnection(conString);
//1.Connection to a database
//using declaration for OLE DB
using System.Data.OleDb;
//specify the ConnectionString property
publicstringconString=@“Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=.\\PersonDatabase.mdb”;
//Initializes a new instance of the OleDbConnection
OleDbConnection con = new OleDbConnection (conString);
2. DataSet
The DataSet is similar to an array of disconnected Recordset objects. It supports disconnected
data access and operations, allowing greater scalability because you no longer have to be
connected to the database all the time. DataSet is a copy of a extracted data being downloaded
and cached in the client system.
DataSet object is made up of two objects:
• DataTableCollection Object containing null or multiple DataTable objects(Columns, Rows,
Constrains)
• DataRelationCollection Object containing null or multiple DataRelation objects
which establishes a parent/child relation between two DataTable objects.
//Create a DataSet
DataSet dset = new DataSet();
There are two types of DataSets:
Typed Dataset
Typed dataset is derived from the base DataSet class and then uses information in an XML
Schema file (.xsd file) in order to generate a new class. Information from the schema (tables,
columns, and so on) is generated and compiled into this new dataset class as a set of first-class
objects and properties. Typed dataset is easier to read.It?s also supported by IntelliSense in
the Visual Studio Code Editor. r /> At compile time, it has type checking so that there are less
errors in assigning values to dataset members.
Using Typed dataset has many advantages.
LOVELY PROFESSIONAL UNIVERSITY 87