Handling of data from multiple databases. Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
1 Chapter 12 Working With Access 2000 on the Internet.
VBA Modules, Functions, Variables, and Constants
Automating Tasks With Macros
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Using Objects and Properties
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Visual Basic Database Access BICS546. Microsoft Universal Data Access OLE DB: The OLE database protocol –Allows a program to access information in any.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Component 8, Slide 1 CP2030 Visual basic for C++ Programmers, ‘The VB Team’ Copyright © University of Wolverhampton CP2030 Visual Basic For C++ Programmers.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
1 Chapter 5: Introduction To Form Builder. 2 Forms  Why Do We Use Form Builder?  Why Don’t We Use SQL Only?!
WORKING WITH FILES, MENUS AND DATABASES IN VISUAL BASIC BY V. V. SUBRAHMANYAM.
Chapter 8 Relational Databases ActiveX Database Controls 8 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
Automating Tasks with Visual Basic. Introduction  When can’t find a readymade macro action that does the job you want, you can use Visual Basic code.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Interacting with Databases Chapter 10. VB and Databases u It is often useful to have a VB program access data stored in a file other than a text file.
Using Visual Basic 6.0 to Create Web-Based Database Applications
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Chapter 15: Using LINQ to Access Data in C# Programs.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 6 – Designing.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
Database Management School of Business Eastern Illinois University © Abdou Illia, Fall 2002 (Week 16, Monday 12/09/2002)
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
You can use Access forms to create an interface to your reports and queries. You can add: Buttons to initiate reports and queries Combo Boxes, List.
Microsoft Office 2007 Access Chapter 3 Maintaining a Database.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
With Microsoft Office 2007 Introductory© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Introductory.
There are seven main components of a database in Access 2000: Tables. Use tables to store database information. Forms Use forms to enter or edit the information.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 6 1 Microsoft Office Access 2003 Tutorial 6 – Creating Custom Forms.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
1 Chapter 6: Creating Oracle Data Block Forms. 2 Forms  Application with a graphical user interface that looks like a paper form  Used to insert, update,
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Data Access Objects .
Database vs. DBMS Database Database Management System
Developing Forms and Subforms.
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
CIS16 Application Programming with Visual Basic
Working With Databases
Unit J: Creating a Database
Unit – V Data Controls.
Presentation transcript:

Handling of data from multiple databases

Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application provides the interface between the user and the database interface allows the user to tell the database what he or she needs allows the database to respond to the request displaying the requested information in some manner

A Visual Basic application cannot directly interact with a database There are two intermediate components between the application and the database –data control –database engine

Data control It is a Visual Basic object It connects the application to the database via the database engine. It is the conduit between the application and the engine, passing information back and forth between the two Database engine It is the heart of a Visual Basic database management system It is the actual software that does the management. Having this engine saves programmers a lot of work. The database engine native to Visual Basic is known as the Jet engine. It is the same engine used by Microsoft Access for database management. Hence, it is primarily used to work with Access databases, but it can also work with others. It requires less code to connect to an existing database View all information within that database modify any and all information within that database Add and delete all information within that database

ID No Bob Jones Mary Rodgers Sue Williams Name Date of Birth 01/04/58 WeightHeight Field Record Table 11/22/61 06/11/ Simple database

Data Access Object (DAO) It is a structure of objects for accessing databases through your code. All the functionality of the Data control is also available to your code, through the DAO. Record Set: Record sets are objects that represent collections of records from one or more tables. You can’t access the tables of a database directly. The only way to view or manipulate records is via RecordSet object. A RecordSet is constructed of columns and rows and is similar to a table. But it can contain data from multiple table. Three types of RecordSets are DynaSets  Which are updatable views of data SnapShots  Which are static( read only) views of data Tables  Which are direct views of tables.

Three types of recordsets, established via the RecordsetType property: TableRepresentation of a native database table (not formed via a query). You can add, change, or delete records. DynasetThe default type, a Dynaset is formed as the result of a database query. You can add, change, or delete records from the underlying table(s). This is the most flexible Recordset type. SnapshotA static copy of records that cannot be updated. Used if you are just viewing or searching a database table.

DAO Data Control The DAO data control is selected from the Visual Basic toolbox window. It’s icon looks like this: The DAO data control is the primary interface between a Visual Basic application and a database The data control (or tool) can access databases created by other programs besides Visual Basic (or Microsoft Access)

The data control can perform the following tasks 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 to the database, or data bound controls. Add new records, delete records, or update records. Trap any errors that may occur while accessing data. Close the database.

DAO Data Control Properties Important properties of this data control are: AlignDetermines where data control is displayed. CaptionPhrase displayed on the data control. ConnectType of database. Default is Microsoft Access (or Jet). DatabaseNameReturns or sets the name of the source database for the data control. Must be a fully qualified path and file name. ExclusiveIndicates whether the underlying database is opened for single- user or multi-user access. ReadOnlyIndicates whether the data can be edited or not. RecordsetA set of records defined by a data control’s Connect, DatabaseName, and RecordSource properties. Run-time only. RecordsetTypeIndicates type of Recordset you want data control to create RecordSourceDetermines the table (or virtual table) the data control is attached to. VisibleEstablishes whether the data control appears on the form at run-time.

Move to first record (row) Move to last record (row) Move to next record (row) Move to previous record (row) After placing a DAO data control on a form, set the DatabaseName property first. Then, set the RecordSource property. Recordset Object When we set the RecordSource property (either select a table from the database or form a virtual table via a query) The data control (using the Jet engine) retrieves the needed records and places them in the Recordset object for our use.

The relationship between the data control, its two primary properties (DatabaseName and RecordSource), and the Recordset object is:

Data Bound Controls To view the information, we use data bound controls that are special controls with properties established by database fields A data bound control is needed for each field (column) in the Recordset (database table) you need to view Standard data bound data controls are: LabelCan be used to provide display-only access to a specified text data field. Caption property is data bound. Text BoxCan be used to provide read/write access to a specified text data field. Probably, the most widely used data bound tool. Text property is data bound. Check BoxUsed to provide read/write access to a Boolean field. Value property is data bound. Picture BoxUsed to display a graphical image from a bitmap, icon, gif, jpeg, or metafile file. Provides read/write access to a image/binary data field. Picture property is data bound. Image BoxUsed to display a graphical image from a bitmap, icon, gif, jpeg, or metafile file (uses fewer resources than a picture box). Provides read/write access to a image/binary data field. Picture property is data bound.

Data Bound Control Properties DataChangedIndicates whether a value displayed in a bound control has changed. DataFieldSpecifies the name of a field in the table pointed to by the respective data control. DataSourceSpecifies which data control the control is bound to (indirectly specifying the database table).

Follow these steps (in order listed) in placing the controls on a form: Draw the bound control on the same form as the data control to which it will be bound Set the DataSource property. Click on the drop-down arrow to list the data controls on your form. Choose one Set the DataField property. Click on the drop-down arrow to list the fields associated with the selected data control records. Make your choice Set all other properties, as needed

The relationships between a data bound control (DataSource and DataField properties) and the DAO data control (Recordset property) are:

DAO Data Control Events Important DAO data control events: ErrorTriggered when a data access error occurs and Visual Basic code is not being executed. RepositionTriggered after data control pointer moves to a new record. Use to update information from non-data bound controls. ValidateEvent triggered when the pointer is about to move away from the current record. This event can be used to cancel an update of a record or a move to a new record.

DAO Data Control Methods important methods. These methods perform certain actions on the data control: RefreshRequeries the database based on contents of the RecordSource property. UpdateControlsRestores the value of bound controls to original values (if no update has been performed). UpdateRecordSaves the values of bound controls to the database without triggering the data control Validate event.

DAO Data Control Recordset Properties Important data control Recordset properties are: AbsolutePositionLong integer that either gets or sets the position of the current record. BOFReturns True when the current record is positioned before any data. BookmarkSets or returns a bookmark to the current record. Used as a place marker in database management tasks. EditModeIndicates the state of editing for the current record. EOFReturns True when the current record is positioned past any data. PercentPositionSingle data type that sets or gets the position of the current record as a percentage of total records. Used for status indicators. RecordCountThe total number of records in the Recordset. UpdatableRead-only at run-time. If True, records in the Recordset can be modified. If False, records are read-only.

DAO Data Control Recordset Methods Important Recordset methods are: AddNewAdds a new record to the Recordset. All fields are set to null and this record becomes the current record. CancelUpdateUsed to cancel any pending updates (either with Edit or AddNew method) CloseCloses a Recordset. DeleteThe current record is deleted from the Recordset. EditPlaces the current record in the Recordset into edit mode. MoveFirstMoves the current record pointer to the first record in the Recordset. MoveLastMoves the current record pointer to the last record in the Recordset. MoveNextMoves the current record pointer to the next record in the Recordset. MovePrevious Moves the current record pointer to the previous record in the Recordset. RequeryUpdates the data in a Recordset object by re-executing the query on which the object is based. UpdateSaves the current contents of all data bound controls.

Private Sub cmdPrevious_Click() datTitles.Recordset.MovePrevious If datTitles.Recordset.BOF Then datTitles.Recordset.MoveFirst End If End Sub Private Sub cmdNext_Click() datTitles.Recordset.MoveNext If datTitles.Recordset.EOF Then datTitles.Recordset.MoveLast End If End Sub

DAO Example Dim wstemp As Workspace Dim dbtemp As Database Dim rstemp As Recordset Set wstemp = DBEngine.Workspaces(0) Set dbtemp = wstemp.OpenDatabase("", False, False, "ODBC;DSN=Oracle;USR=scott;PWD=tiger") Set rstemp = dbtemp.OpenRecordset(myquery.Text, dbOpenDynaset, dbSQLPassThrough) howmany = 0 Combo1.Clear Do Until rstemp.EOF msgbox rstemp(0) rstemp.MoveNext howmany = howmany + 1 Loop