Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database...

23
2003 : . Copyright Ismail M Rom , . i PPU All Rights Reserved 1 Lab10 Lab10 Interacting Interacting with Data with Data (Database (Database Management) Management)
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    213
  • download

    1

Transcript of Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database...

Page 1: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

1

Lab10Lab10

Interacting with Interacting with DataData

(Database Management)(Database Management)

Page 2: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

2

Database ConceptDatabase Concept• Database: An integrated collection of data.

• Table: One data file (Set of records).

• Dbase: Collection of tables.

• Record: Set of fields.

• Field: Set of characters.

• Index: A key field with unique values for every record.

Page 3: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

3

Flat-File (Table)

Row - Record

Fields - Columns

Database Concept …[CONT]Database Concept …[CONT]

Page 4: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

4

• Relational Database: Collection of tables in which no duplicate data is found.

• Database file Extension: FileName.MDB

• Ms-Database(MDB) Contents:– Tables– Reports– Forms– Queries

Database Concept …[CONT]Database Concept …[CONT]

Page 5: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

5

Creating New DatabaseVisual Data Manager: A program available

with in the VB environment used to create databases.

V.Data Manager Tasks:– Create a new database.– Enter A new data into data file.– Edit existing dbase.– Searching.

Page 6: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

6

Executing Visual Data ManagerExecuting Visual Data Manager1- From Add-Ins menu select Visual Data Manager.

2- Visual Data Window appears.

Visual Data Window

Page 7: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

7

Creating DatabaseCreating Database

1- File menu => New => Microsoft Access => version 7.0 MDB.

2- Save the new database in the dialog box that appears.

3- The DataBase window will appear:

Database format ( MsAccess,Dbase, FxPro …)

Page 8: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

8

4- Select Properties.

•Right Click the mouse.

•Choose New Table.

Page 9: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

9

Creating Database …Creating Database …. [. [CONT]CONT]

5- Add Table Name.

•Add the Fields & Indexes.

•Build the Table.

Page 10: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

10

Using the DatabaseUsing the DatabaseYou can add, update, delete data from the

database as follow:

• Open the Dbase in the Database window.

• Open the table ( Double click or Right click to the mouse).

• Add, Update, Delete data.

• Close to return to the database window.

Page 11: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

11

Data ControlData ControlThe data control enables you to access the

database.

• Add data control to the form.

• Specify the following properties:– Database name– Record source– Caption.

Page 12: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

12

Linking Dbase fields with form’s ControlsLinking Dbase fields with form’s Controls

• Choose Label or Textbox control

• Change the following properties:– Data source (the data control name)– Data field. ( table field name )

Page 13: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

13

Advanced Data Control UsageAdvanced Data Control UsageData Control Methods:

• MoveFirst, MoveLast, MoveNaxt, MovePrevious, AddNew, Delete.

Using Data Control Methods:

Syntax

DatacontrolName. Recordset.Method

Example:

Data1.RecordSet.AddNew

Page 14: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

14

Data Control Properties • Data1.Recordset.EOF return True when reach the end of the file

(table)• Data1.Recordset.BOF return True when reach the beginning of the

file (table)• Data1.Recordset.Fields(“fieldname”).value returns the value of the field

Page 15: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

15

ADO Data ControlADO Data ControlData Grid ControlData Grid Control

• ADO stands for: ActiveX Data Object

• ADO data control : Enables accessing the database by VB program.

• Data Grid Control: Display in a table format the data requested form the database.

Page 16: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

16

Adding ADO & Data Grid Controls to Adding ADO & Data Grid Controls to the ToolBoxthe ToolBox

• From the project menu select components (CTRL T)

• From the dialog box select: – Microsoft ADO Data control 6.0.– Microsoft DatGrid Control 6.0.

• Click Ok button.

Now you can see two new controls appears at the end of the tool box.

Page 17: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

17

Designing ADO ControlDesigning ADO Control• Add the ADO control to the form.• Change the following properties:• Connection String:

– Provider : Microsoft jet 3.51 OLE DB Provider.– Select Dbase name.– Test Connections.

• Record Source: – Command Type: 2-adcmdTable.– Table: TableName– Apply

Page 18: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

18

Designing Data Grid ControlDesigning Data Grid Control

• Add Data Grid control to the form.

• Change the following properties:

• Data Source: Specify the ADO Name.

• Right Click the mouse.

• Select Retrieve Fields.

• From properties window assign the access type to the database ( Add, Delete….).

Page 19: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

19

Data Grid Control PropertiesData Grid Control Properties

• AllowAddNew (True/False): Enables to add new records.

• AllowUpdate(True/False): Enables to update records.

• AllowDelete(True/False): Enables to delete a specified record.

Page 20: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

20

Data Grid Control PropertiesData Grid Control Properties

• Col: (Column number): Enables you to specify a column.

• Row( Row Number): enables you to specify a row.

• Text: The text in the specified cell from Row&Col.

• Example:Datagrid1.Row=0: Datagrid1.Col=0

Print Datagrid1.text

Page 21: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

21

Lab TrainingUsing the MDI, design the following interface

Page 22: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

22

Lab Training [CONT]

Page 23: Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)

Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved

23

Lab10Lab10

EndEnd