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

3rd Year Paper - 1 Unit 5

Uploaded by

Ayushi Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

3rd Year Paper - 1 Unit 5

Uploaded by

Ayushi Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Paper -1 unit 5

Data Access Using the ADO Data Control & Report Generation

What Does ActiveX Data Objects (ADO) Mean?


ActiveX Data Objects (ADO) is a collection of software components providing a programmatic
interface to access the data sources from client applications. ADO acts as a layer to access any data
store in a generic way from the application code. It eliminates the need to possess the knowledge of
database implementation and reduces the complexity of dealing with the low level code needed to
handle the data.

Released in 1996, activeX data object (ADO) originated from the concept of RDO (remote data
object) and DAO (data access object). One of the constituents of MDAC (Microsoft data access
components), ADO and other MDAC constituents provides a framework of components used by
client applications to access SQL, semi-structured and legacy data stores.

ADO.NET is an advanced data access technology designed to work in the .NET environment and is
based on the disconnected model for data access. While ADO uses COM (Component Object Model)
technology for providing data access service from unmanaged code, ADO.NET depends on managed
providers of the CLR (Common Language Runtime) of the .NET framework.

Explains ActiveX Data Objects (ADO)

ADO uses an OLEDB provider for connecting to the data sources and accessing data. OLEDB is a
component based programmatic interface provided to interact with different data sources. These data
sources can be both relational and non-relational databases such as object databases, web pages,
spreadsheets or e-mail messages. Prior to OLEDB and ADO, ODBC (open database connectivity) was
the popular model used in applications across platforms.

The object model of ADO contains four collections of twelve objects. The different collections are
fields, properties, parameters and errors. Each collection consists of the following twelve objects:

1. Connection - for connecting to data source through OLE DB


2. Command - for sending an instruction (SQL query or stored procedure) to data provider
3. Recordset - a group of records representing the data
4. Immediate - a recordset locked in optimistic or pessimistic way
5. Batch - for committing or doing a rollback database transaction
6. Transaction - the database transaction
7. Record - a set of fields
8. Stream - for reading and writing a stream of bytes
9. Parameter - for changing the functionality
10. Field - a column in the database
11. Property - the ability of OLEDB provider
12. Error - the error faced by the OLEDB provider during its execution

ADO 2.8 is the latest version and has the following features:

 Components: These are used for data access and manipulation from a variety of sources to
offer benefits like ease of use, faster access, low memory overhead and a small disk footprint.
 ADO MD (MultiDImensional): This is used to access multidimensional data like CubeDef
and CellSet objects.
 RDS (Remote Data Services): This is for retrieval and update of data in the server from a
client in a single transaction.
 ADOX (ADO Extensions): This is an additional set of components used to create and
maintain objects related to schema (tables or procedures) and security (user and group).

ADO Components
ActiveX Data Objects consists of a generic-style data-access structure that allows you to
access any data source, regardless of its structure, with the same programming interface. The
individual objects within the ADO object model are used to provide all of the data-storage,
manipulation, and retrieval commands needed when writing a data-based application. ADO
includes the following objects and collections:

 The Connection object


 The Command object
 The Parameters collection and the Parameter object
 The Record set object
 The Fields collection and the Field object
 The Record and Stream objects
 The Properties collection and the Property object
 The Errors collection and the Error object

In the next sections, I take a closer look at these objects and collections.

The Connection Object

The Connection object is the gateway for all data communications through ActiveX Data
Objects. Figure 2-1 illustrates the Connection object’s object model.

Figure 2-1. The Connection object’s object model

In order to access data from any source, a connection for that source must first be established.
ADO uses the Connection object to accomplish this. The Connection object uses information
that you provide to establish a unique connection to a particular OLE DB data source. The
standard information that a Connection object accepts includes filenames, data-provider
names, usernames, and passwords.

Applications communicate with a database, firstly, to retrieve the data stored there and
present it in a user-friendly way, and secondly, to update the database by inserting, modifying
and deleting data.

Microsoft ActiveX Data Objects.Net (ADO.Net) is a model, a part of the .Net framework that
is used by the .Net applications for retrieving, accessing and updating data.
ADO.Net Object Model

ADO.Net object model is nothing but the structured process flow through various
components. The object model can be pictorially described as −

The data residing in a data store or database is retrieved through the data provider. Various
components of the data provider retrieve data for the application and update data.

An application accesses data either through a dataset or a data reader.

 Datasets store data in a disconnected cache and the application retrieves data from it.
 Data readers provide data to the application in a read-only and forward-only mode.

Data Provider
A data provider is used for connecting to a database, executing commands and retrieving
data, storing it in a dataset, reading the retrieved data and updating the database.

The data provider in ADO.Net consists of the following four objects −

Sr.No. Objects & Description


Connection
1
This component is used to set up a connection with a data source.
Command
2
A command is a SQL statement or a stored procedure used to retrieve, insert, delete or
modify data in a data source.
DataReader
3
Data reader is used to retrieve data from a data source in a read-only and forward-only
mode.
DataAdapter

This is integral to the working of ADO.Net since data is transferred to and from a
4
database through a data adapter. It retrieves data from a database into a dataset and
updates the database. When changes are made to the dataset, the changes in the
database are actually done by the data adapter.

There are following different types of data providers included in ADO.Net

 The .Net Framework data provider for SQL Server - provides access to Microsoft
SQL Server.
 The .Net Framework data provider for OLE DB - provides access to data sources
exposed by using OLE DB.
 The .Net Framework data provider for ODBC - provides access to data sources
exposed by ODBC.
 The .Net Framework data provider for Oracle - provides access to Oracle data source.
 The EntityClient provider - enables accessing data through Entity Data Model (EDM)
applications.

DataSet
DataSet is an in-memory representation of data. It is a disconnected, cached set of records
that are retrieved from a database. When a connection is established with the database, the
data adapter creates a dataset and stores data in it. After the data is retrieved and stored in a
dataset, the connection with the database is closed. This is called the 'disconnected
architecture'. The dataset works as a virtual database containing tables, rows, and columns.

The following diagram shows the dataset object model −

The DataSet class is present in the System.Data namespace. The following table describes all
the components of DataSet −
Sr.No. Components & Description
DataTableCollection
1
It contains all the tables retrieved from the data source.
DataRelationCollection
2
It contains relationships and the links between tables in a data set.
ExtendedProperties
3
It contains additional information, like the SQL statement for retrieving data, time of
retrieval, etc.
DataTable
4
It represents a table in the DataTableCollection of a dataset. It consists of the
DataRow and DataColumn objects. The DataTable objects are case-sensitive.
DataRelation
5
It represents a relationship in the DataRelationshipCollection of the dataset. It is used
to relate two DataTable objects to each other through the DataColumn objects.
DataRowCollection
6
It contains all the rows in a DataTable.
DataView
7
It represents a fixed customized view of a DataTable for sorting, filtering, searching,
editing and navigation.
PrimaryKey
8
It represents the column that uniquely identifies a row in a DataTable.
DataRow

It represents a row in the DataTable. The DataRow object and its properties and
9
methods are used to retrieve, evaluate, insert, delete, and update values in the
DataTable. The NewRow method is used to create a new row and the Add method
adds a row to the table.
DataColumnCollection
10
It represents all the columns in a DataTable.
DataColumn
11
It consists of the number of columns that comprise a DataTable.

Connecting to a Database
The .Net Framework provides two types of Connection classes −

 SqlConnection − designed for connecting to Microsoft SQL Server.


 OleDbConnection − designed for connecting to a wide range of databases, like
Microsoft Access and Oracle.

Example 1
We have a table stored in Microsoft SQL Server, named Customers, in a database named
testDB. Please consult 'SQL Server' tutorial for creating databases and database tables in SQL
Server.

Let us connect to this database. Take the following steps −

 Select TOOLS → Connect to Database

 Select a server name and the database name in the Add Connection dialog box.

 Click on the Test Connection button to check if the connection succeeded.


 Add a DataGridView on the form.

 Click on the Choose Data Source combo box.


 Click on the Add Project Data Source link.

 This opens the Data Source Configuration Wizard.


 Select Database as the data source type
 Choose DataSet as the database model.

 Choose the connection already set up.

 Save the connection string.


 Choose the database object, Customers table in our example, and click the Finish
button.

 Select the Preview Data link to see the data in the Results grid −

When the application is run using Start button available at the Microsoft Visual Studio tool
bar, it will show the following window −

What is the difference between ADO, RDO and DAO?


DAO ADO RDO
Data Access Object is used Active Data Object is more Remote Data Object is used
for accessing data before powerful till Date. It is for Accessing remote data.
ADO. nothing but combination of
both DAO and RDO.
DAO can access MS-Access ADO is universal data access RDO can access client server
Database. object, it can access both database.
relational and non relational
database.
In this control set the In this control, set In this control, set
DatabaseName and Record ConnectionString and DataSourceName and SQL
Source Property. RecordSource property. property.

SQL
SQL is a database computer language designed for the retrieval and management of data in a
relational database. SQL stands for Structured Query Language. This tutorial will give you
a quick start to SQL. It covers most of the topics required for a basic understanding of SQL
and to get a feel of how it works.

SQL is Structured Query Language, which is a computer language for storing, manipulating
and retrieving data stored in a relational database.

SQL is the standard language for Relational Database System. All the Relational Database
Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres
and SQL Server use SQL as their standard database language.

Also, they are using different methods, such as −

 MS SQL Server using T-SQL,


 Oracle using PL/SQL,
 MS Access version of SQL is called JET SQL (native format) etc.

Applications of SQL
As mentioned before, SQL is one of the most widely used query language over the databases.
I'm going to list few of them here:

 Allows users to access data in the relational database management systems.


 Allows users to describe the data.
 Allows users to define the data in a database and manipulate that data.
 Allows to embed within other languages using SQL modules, libraries & pre-
compilers.
 Allows users to create and drop databases and tables.
 Allows users to create view, stored procedure, functions in a database.
 Allows users to set permissions on tables, procedures and views.
Process of SQL
When we are executing the command of SQL on any Relational database management
system, then the system automatically finds the best routine to carry out our request, and the
SQL engine determines how to interpret that particular command.

Structured Query Language contains the following four components in its process:

 Query Dispatcher
 Optimization Engines
 Classic Query Engine
 SQL Query Engine, etc.

A classic query engine allows data professionals and users to maintain non-SQL queries. The
architecture of SQL is shown in the following diagram:

Some SQL Commands


The SQL commands help in creating and managing the database. The most common SQL
commands which are highly used are mentioned below:

1. CREATE command
2. UPDATE command
3. DELETE command
4. SELECT command
5. DROP command
6. INSERT command

CREATE Command

This command helps in creating the new database, new table, table view, and other objects of
the database.

UPDATE Command

This command helps in updating or changing the stored data in the database.

DELETE Command
This command helps in removing or erasing the saved records from the database tables. It
erases single or multiple tuples from the tables of the database.

SELECT Command

This command helps in accessing the single or multiple rows from one or multiple tables of
the database. We can also use this command with the WHERE clause.

DROP Command

This command helps in deleting the entire table, table view, and other objects from the
database.

INSERT Command

This command helps in inserting the data or records into the database tables. We can easily
insert the records in single as well as multiple rows of the table.

SQL vs No-SQL
The following table describes the differences between the SQL and NoSQL, which are
necessary to understand:

SQL No-SQL
1. SQL is a relational database management 1. While No-SQL is a non-relational or
system. distributed database management system.
2. The query language used in the No-SQL
2. The query language used in this database
database systems is a non-declarative query
system is a structured query language.
language.
3. The schema of SQL databases is 3. The schema of No-SQL databases is a
predefined, fixed, and static. dynamic schema for unstructured data.
4. These databases are vertically scalable. 4. These databases are horizontally scalable.
5. The database type of SQL is in the form
5. The database type of No-SQL is in the form
of tables, i.e., in the form of rows and
of documents, key-value, and graphs.
columns.
6. It follows the ACID model. 6. It follows the BASE model.
7. Complex queries are easily managed in 7. NoSQL databases cannot handle complex
the SQL database. queries.
8. This database is not the best choice for 8. While No-SQL database is a perfect option
storing hierarchical data. for storing hierarchical data.
9. All SQL databases require object- 9. Many No-SQL databases do not require
relational mapping. object-relational mapping.
10. Gauges, CircleCI, Hootsuite, etc., are
10. Airbnb, Uber, and Kickstarter are the top
the top enterprises that are using this query
enterprises that are using this query language.
language.
11. SQLite, Ms-SQL, Oracle, PostgreSQL, 11. Redis, MongoDB, Hbase, BigTable,
and MySQL are examples of SQL database CouchDB, and Cassandra are examples of
systems. NoSQL database systems.
Advantages of SQL
SQL provides various advantages which make it more popular in the field of data science. It
is a perfect query language which allows data professionals and users to communicate with
the database. Following are the best advantages or benefits of Structured Query Language:

1. No programming needed

SQL does not require a large number of coding lines for managing the database systems. We
can easily access and maintain the database by using simple SQL syntactical rules. These
simple rules make the SQL user-friendly.

2. High-Speed Query Processing

A large amount of data is accessed quickly and efficiently from the database by using SQL
queries. Insertion, deletion, and updation operations on data are also performed in less time.

3. Standardized Language

SQL follows the long-established standards of ISO and ANSI, which offer a uniform
platform across the globe to all its users.

4. Portability

The structured query language can be easily used in desktop computers, laptops, tablets, and
even smartphones. It can also be used with other applications according to the user's
requirements.

5. Interactive language

We can easily learn and understand the SQL language. We can also use this language for
communicating with the database because it is a simple query language. This language is also
used for receiving the answers to complex queries in a few seconds.

6. More than one Data View

The SQL language also helps in making the multiple views of the database structure for the
different database users.

Disadvantages of SQL
With the advantages of SQL, it also has some disadvantages, which are as follows:

1. Cost

The operation cost of some SQL versions is high. That's why some programmers cannot use
the Structured Query Language.

2. Interface is Complex
Another big disadvantage is that the interface of Structured query language is difficult, which
makes it difficult for SQL users to use and manage it.

3. Partial Database control

The business rules are hidden. So, the data professionals and users who are using this query
language cannot have full database control.

Ques. Data Report in Visual Basic


Creating a Data Report in Visual Basic 6 (VB6)

1. Start a new Standard EXE project.


2. On the Project menu, click Add Data Environment. ...
3. We need to point to our database. ...
4. We now tell the Data Environment what is in our database. ...
5. Click OK. ...
6. Display the properties window and give the data environment a name property of
denPhone.
7. Creating a Data Report
8. Once the Data Environment has been created, we can create a Data Report. We will
drag things out of the Data Environment onto a form created for the Data Report, so
make sure your Data Environment window is still available.
9. 1. On the Project menu, click Add Data Report and one will be added to your project.
If this item is not on the menu, click Components. Click the Designers tab, and choose
Data Report and click OK to add the designer to your menu.
10. 2. Set the following properties for the report:
11. Name - rptPhone
Caption - Phone Directory
DataSource - denPhone (your phone data environment - choose, don’t type)
DataMember - PhoneList (the table name - choose don’t type)
12. 3. Right-click the Data Report and click Retrieve Structure. This establishes a
report format based on the Data Environment.
13. 4. Note there are five sections to the data report: a Report Header, a Page Header, a
Detail section, a Page Footer, and a Report Footer. The headers and footers contain
information you want printed in the report and on each page. To place information in
one of these regions, right-click the selected region, click Add Control, then choose
the control you wish to place. These controls are called data report controls and
properties are established just like you do for usual controls. Try adding some
headers.
14. 5. The Detail section is used to layout the information you want printed for each
record in your database. We will place two field listings (Name, Phone) there. Click
on the Name tab in the Data Environment window and drag it to the Detail section of
the Data Report. Two items should appear: a text box Name and a text box Name
(PhoneList). The first text box is heading information. Move this text box into the
Page Header section. The second text box is the actual value for Name from the
PhoneList table. Line this text box up under the Name header. Now, drag the Phone
tab from the Data Environment to the Data Report. Adjust the text boxes in the same
manner. Our data report will have page headers Name and Phone. Under these
headers, these fields for each record in our database will be displayed. When done, the
form should look something like this:
15.
16. In this form, I’ve resized the labels a bit and added a Report Header. Also, make sure
you close up the Detail section to a single line. Any space left in this section will be
inserted after each entry.
17. 6. Click File and Save rptPhone As. Save the environment in an appropriate folder.
We will now reopen our phone database manager and attach this and the data
environment to that project and add capabilities to display the report.

Data Environment
Data Environment object is created and managed using Data Environment designer. A Data
Environment object can accomplish any of the following tasks.

• Can contain connection and command objects


• Can establish relationship between command object to represent hierarchies
• Can group data and get aggregates
• Allows fields to be dragged and dropped on to a Data Report, for report, and a Form for data entry
screen
• Can work as source for Databound control such as DataCombo controls and Hierarchical Flexgrid
control.
In order to work with Data Environment object, you have to add Data Environment Designer to your
project. Data Environment Designer allows programmer to accomplish any of the tasks mentioned
above. Data Environment Designer is invoked when you double click on Data Environment object in
Project Explorer.

To add Data Environment object to the project:

1. Select Project-> Add Data Environment. If Add Data Environment option is not found then select
More ActiveX Designers and then select Data Environment.

Note: Visual Basic adds Data Environment Designer to your project and also creates a connection
object.

Data Environment Designer

Working with Connection Object


Whenever you create a Data Environment object a Connection object is added to Data Environment
object. But that Connection object is not connected to any database. So first we have to establish a
connection with the Connection object. Now, let us see how to connect to database through
Connection object.
The Data Environment designer provides an interactive, environment for creating
programmatic data access. At design time, you set property values for Connection and
Command objects, write code to respond to ActiveX Data Object (ADO) events, execute
commands, and create aggregates and hierarchies. You can also drag Data Environment
objects onto forms or reports to create data-bound controls.
With the Data Environment designer, you can accomplish the following tasks:

 Add a Data Environment designer to a Visual Basic project.


 Create Connection objects.
 Create Command objects based on stored procedures, tables, views, synonyms,
and SQL statements.
 Create hierarchies of commands based on a grouping of Command objects, or by
relating one or more Command objects together.
 Write and run code for Connection and Recordset objects.
 Drag fields within a Command object from the Data Environment designer onto a
Visual Basic form or the Data Report designer.

Examine the connection to database introduction to crystal report


generator

It is included in all major editions and ships in all languages available with Visual
Studio .NET. Crystal Reports .NET provides developers with the fastest, most productive
way to create and integrate presentation-quality, interactive reports that scale to meet the
demands of end users. This article introduces you to Crystal Reports .NET and shows you
how to create reports and view them in either a Windows form or a Web form. I will also
show you how to publish a report as a Web service and consume the service in a Web form.

There are a wide variety of available sources for feeding data into your report. You can use
an OLE DB provider, ODBC data source, ADO.NET dataset, and even an XML Web service.

Crystal Reports .NET is a very powerful report writer. It offers a very well defined object
model that provides flexibility when integrating reports into Windows and Web applications.
It also comes with a highly customizable viewer component that gives developers control on
how their reports are presented to users. This article examines some of the new features of
Crystal Reports .NET and shows you how to integrate a report into your application. After
creating this report, you will learn how to publish its content to the Web as a Web service.

New Features in Crystal Reports .NET


Integrated into .NET IDE

Crystal Reports .NET has been completely re-written from the ground-up in C#. It is tightly
integrated into the Visual Studio .NET IDE. Developers no longer have to switch to a

Crystal Reports Viewer

Crystal Reports .NET provides developers with two different report viewing components.
The first can be used for displaying reports in Windows forms. The other is a component that
can be used to display reports in a Web environment. The beauty of these viewers is in their
simplicity. Viewing a report is as simple as setting the ReportSource property of the
respective viewer.

Allowing users to interact with the report


Developers can give users the ability to interact with their reports object via a programmable
API. Developers can change report properties by calling methods or setting properties of the
viewer object.

ADO.NET Integration

ADO.NET is now the lingua-franca of data interchange in the .NET world. Crystal
Reports .NET provides the ability to use ADO.NET datasets as the data source for reports.

Expose Reports as Web Services

Reports can be exposed as Web services. This adds additional power to Web service
applications. Exposing reports as Web services enables developers to offer real-time
information (in the form of a report) as opposed to real-time data!

Designing and Viewing a Report in Crystal Reports .NET


The major focus of this article is to show you how to create a complex report using Crystal
Reports .NET and SQL Server 2000. The report will use data from the SQL Server database
called Northwind. The specification for this report is:

1. Show a list of all Products grouped by Category.

1. 2. Display the Quantity on Hand, Unit Price, Re-order Level and value of each
product.
2. 3. Show a count and total value of all products in stock by category and an overall
count and total value.
3. 4. Highlight all products where the quantity on hand has fallen below the re-order
level.
4. 5. Limit the report products that have not been discontinued.

You might also like