26
CHAPTER 9 CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali 1

CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Embed Size (px)

Citation preview

Page 1: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

CHAPTER 9CHAPTER 9DATABASE MANAGEMENT

© Prepared By:Razif Razali 1

Page 2: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

CONTENTSCONTENTS

Visual Basic and Database FilesADO Data ControlViewing a Database FileNavigating the DatabaseUpdating a Database File

© Prepared By:Razif Razali

2

Page 3: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

IntroductionIntroduction

All business applications need to store large volumes of data organized in a format so that information can be retrieved efficiently and quickly as and when required.

With the help of a DBMS (Database Management System), managing the data becomes easy.

A DBMS is a system that manages the storage and retrieval of data in a database.

Further Microsoft Visual Basic provides tools for creating and accessing a variety of RDBMS (Relational Database Management System).

An RDBMS stores and retrieves information according to the relationship defined.

In a RDBMS, the data is the container of the tables in which all data is stored in the relationships is formed by data values.

A database is a collection of data that is related one to another to support a common application. For example Employee details - Name, Address, etc. Each of these collections of data continue a database.

Database accessing methods are as follows;◦ Jet Engine - Accessing Microsoft Access and Visual Basic databases.◦ ODBC (Open Database Connectivity) - Allow access to the client server

databases on a network.◦ ISAM (Index Sequential Access Method) - Used to access flat databases

such as dBase, FoxPro, ParaDox.© Prepared By:Razif Razali

3

Page 4: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

What is DatabaseWhat is Database

A database is a collection of information. This information is stored in a very structured manner. By exploiting this known structure, we can access and

modify the information quickly and correctly. The tasks of a DBMS are really quite simple. In concept, there are only a few things you can do with

a database:◦ 1. View the data◦ 2. Find some data of interest◦ 3. Modify the data◦ 4. Add some data◦ 5. Delete some data

© Prepared By:Razif Razali

4

Page 5: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Data vs information?What is data?

◦ Data can be defined in many ways.

◦ Information science defines data as unprocessed information.

What is information?◦ Information is data that

have been organized and communicated in a coherent and meaningful manner.

◦ Data is converted into information, and information is converted into knowledge.

◦ Knowledge; information evaluated and organized so that it can be used purposefully.

Page 6: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Why do we need a database?

Keep records of our:◦ Clients◦ Staff◦ Volunteers

To keep a record of activities and interventions;

Keep sales records; Develop reports; Perform research Longitudinal tracking

Page 7: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

What is the ultimate purpose of a What is the ultimate purpose of a database management system?database management system?

DataData InformationInformation KnowledgeKnowledge ActionAction

Page 8: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

ADODCADODC

The ADO (ActiveX Data Object) data control is the primary interface between a Visual Basic application and a database.

It can be used without writing any code at all! Or, it can be a central part of a complex database management system.

This icon may not appear in your Visual Basic toolbox. If it doesn’t,

◦ select Project from the main menu, then click Components. ◦ The Components window will appear. ◦ Select Microsoft ADO Data Control, then click OK. ◦ The control will be added to your toolbox.

The icon for ADODC:

© Prepared By:Razif Razali

8

Page 9: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Using ADODCUsing ADODC

Use of ADODC◦ Connect to a database.◦ Open a specified database table.◦ Create a virtual table based on a database query.◦ Pass database fields to other Visual Basic tools, for

display or editing. Such tools are bound tools (controls), or data aware.

◦ Add new records or update a database.◦ Trap any errors that may occur while accessing data.◦ Close the database.

Refer tutorial URL: http://www.vbtutor.net/lesson25.html

© Prepared By:Razif Razali

9

Page 10: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Microsoft Access ObjectMicrosoft Access Object

A Microsoft Access database file, which has an extension of mdb, contains tables, queries, forms, reports, pages, macros, and modules, which are referred to as database objects.

That’s a lot of information in one large file, but Microsoft Access manages this data quite nicely.

Forms, reports, pages, macros, and modules are generally concerned with letting users work with and display data

© Prepared By:Razif Razali

10

Page 11: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

TableTable

A table contains a collection of data, which is represented by one or more columns and one or more rows of data.

Columns are typically referred to as fields in Microsoft Access, and the rows are referred to as records.

Each field in a table represents an attribute of the data stored in that table.

For example, a field named First_Name would represent the first name of an employee or customer.

This field is an attribute of an employee or customer. A record in a table contains a collection of fields that form

a complete set of attributes of one instance of the data stored in that table.

© Prepared By:Razif Razali

11

Page 12: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Database TableDatabase Table

In this database table, each record represents a single individual.

The fields (descriptors of the individuals) include an identification number (ID No), Name, Date of Birth, Height, and Weight. © Prepared By:

Razif Razali12

Page 13: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

TableTable

Page 14: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

QueryQuery

A query in a database is a group of Structured Query Language (SQL) statements that allow you to retrieve and update data in your tables.

Queries can be used to select or update all of the data in one or more tables or to select or update specific data in one or more tables

© Prepared By:Razif Razali

14

Page 15: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Creating a simple database – Creating a simple database – Using MS AccessUsing MS Access

Refer Access TutorialURL:

http://cisnet.baruch.cuny.edu/holowczak/classes/2200/access/accessall.html

© Prepared By:Razif Razali

15

Page 16: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a DatabaseSteps to Connect a Database

To start using ADODC, you must add ADODC component into your toolbox.

Click Project > Components Select Microsoft ADO Data Control 6.0 (OLEDB)

© Prepared By:Razif Razali

16

Page 17: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database

Add a Adodc control into Form, examples of Adodc control:

Then, by looking at the properties, set the ConnectionString properties, such as

Then, click button Build to continue.

© Prepared By:Razif Razali

17

Page 18: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database

After clicking Build button, the next steps is to choose a Data Link Properties.

Here we choose Microsoft Jet 4.0 OLE DB Provider as our linker.

Then, continue this steps by clicking button Next. Here is where we must tell VB the location and name of

the database we will be using.

© Prepared By:Razif Razali

18

Page 19: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database

Then, select the database file, example:

It is always a good idea to use the Test Connection option.

This way, if there was something wrong with the location or name of the database, we would get an error advising us of this.

If the message inform that the connection is succeeded, it means that your VB have been connected to the database file.

© Prepared By:Razif Razali

19

Page 20: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database After the connection string is built, click OK to dismiss the

property pages for the Data Link. Now the control has the information it needs to connect to the

data source. However, we still need to inform the data control which

table(s) we wish to access. Right click on the ADODC data control again and select

ADODCProperties. Notice that the connection string text box is now filled in:

© Prepared By:Razif Razali

20

Page 21: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database

Next, Click on the RecordSource tab and click the drop down list box for the Command Type.

Select option 2-adCmdTable

© Prepared By:Razif Razali

21

Page 22: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Connect a Database

Now the control knows that we want to access records from a table, and it knows the name of database from when we set up the Data Link.

Now, theTableorStored Procedure Name listbox becomes enabled.

Click the listbox and all of the tables in the database are shown:

© Prepared By:Razif Razali

22

Page 23: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Steps to Bind a Data Source

Assume in the form, there are Textbox which is used to display the informatio in the form.

Example

© Prepared By:Razif Razali

23

Page 24: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Viewing a database using Viewing a database using DataGridView componentDataGridView component

The DataGridView component is a container that allows you to bind data from your data source and have it displayed in a spreadsheet-like format, displaying the columns of data horizontally and the rows of data vertically.

The DataGridView component also provides many properties that allow you to customize the appearance of the component itself, as well as properties that allow you to customize the column headers and the display of data.

URL: http://www.vbtutor.net/lesson26.html

© Prepared By:Razif Razali

24

Page 25: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

Example – Using DataGridViewExample – Using DataGridView

© Prepared By:Razif Razali

25

Page 26: CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali1

THE END

© Prepared By:Razif Razali

26