Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
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.
Using Macros and Visual Basic for Applications (VBA) with Excel
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Access Lesson 2 Creating a Database
Exploring Microsoft Access 2003 Chapter 1 Introduction to Microsoft Access: What Is A Database?
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 1 Databases and Database Objects: An Introduction
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Customizing Word Microsoft Office Word 2007 Illustrated Complete.
Copyright 2003 : Ismail M.Romi, PPU. All Rights Reserved 1 Lab10 Interacting with Data (Database Management)
Copyright © 2001 by Wiley. All rights reserved. Chapter 8: Security, Menus, and Files Security Menu Systems Creating a Memo Editor Using the Clipboard.
Introduction To Form Builder
1 Chapter 5: Introduction To Form Builder. 2 Forms  Why Do We Use Form Builder?  Why Don’t We Use SQL Only?!
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Access Tutorial 10 Automating Tasks with Macros
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 3 Maintaining a Database
Copyright 2007, Paradigm Publishing Inc. BACKNEXTEND 3-1 LINKS TO OBJECTIVES Save a Filter as a Query Save a Filter as a Query Parameter Query Inner, Left,
9-1 Chapter 9 Working with Databases in VB.NET. 9-2 Learning Objectives Understand how databases are used to store business data and how they differ from.
Handling of data from multiple databases. Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
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 Office Access 2003 Số tiết: 30 tiết lý thuyết 60 tiết thực hành Giáo viên: Từ thị Xuân Hiền.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
Analyzing Data For Effective Decision Making Chapter 3.
Numeric Variables Visual Basic for Applications 6.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
Systems Module Slide 2 – Overview and Navigation
McGraw-Hill/Irwin ©2009 The McGraw-Hill Companies, All Rights Reserved Business Driven Information Systems 2e Plug-In T6: Basic Skills and Tools Using.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Copyright © 2001 by Wiley. All rights reserved. Chapter 4: The Selection Process in Visual Basic Selection Process Two Alternative Structure If..Then..ElseIf.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 8 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 8 Creating.
Chapter Two Creating a First Project in Visual Basic.
Why are Databases Better than Files? Multiple users can all use the same database, and have access to the current, up to the minute values for the data.
Windows Forms Navigating database with windows forms.
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.
Databases,Tables and Forms Access Text by Grauer Chapters 1 & 2.
1 Database Systems Introduction to Microsoft Access Part 2.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 3 BACKNEXTEND 3-1 LINKS TO OBJECTIVES Modify a Table – Add, Delete, Move Fields Modify a Table.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 MIS309 Database Systems Introduction to Microsoft Access.
Introduction to a Database Defining a database Database window in Access The six items in window: Tables, Queries Forms, Reports, Macros, Modules.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Gold – Crystal Reports Introductory Course Cortex User Group Meeting New Orleans – 2011.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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 5 1 Microsoft Office Access 2003 Tutorial 5 – Enhancing a Table’s Design.
Using a Database Access97 Please use speaker notes for additional information!
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Access Queries and Forms. Adding a New Field  To insert a field after you have saved your table, open Access, and open the table  It is easier to add.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Access Lessons 1, 2 and 3 ©2009 M and K Solutions, LLC – All Rights Reserved.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
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,
Practical Office 2007 Chapter 10
Database vs. DBMS Database Database Management System
Presentation transcript:

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 1 Chapter 10: Advanced Database Operations

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 2 Revising Vintage Videos 1.Search and display based on a member’s phone number. 2.Browse the member information form and add new members or delete existing members. 3.Display price based on ID number for a video on a Rental form. 4.Add ID number, date and phone number to database for each video that is rented. 5.Search for and display videos with a particular name or partial name to determine if they are in stock. 6.Call the customers who have overdue videos and request they be returned. 7.Check videos back in when they are returned, update the availability status of the video and, if late, calculate late fee.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 3 Plan for Revising Vintage Videos

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 4 Adding Forms to the Project In design mode, use the Project|Add File menu option to add a file to a project. As each form is added, you should immediately use Save frmname.frm as... to save the form. Once all forms have been added, the project must be saved in order for the forms to be made a permanent part of the project.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 5 Validating Video Input Before displaying video name and price, several items should be validated: 1. that the txtVideoID text box is not blank. 2.that the video ID number matches a video on the database. 3.that the video is not already rented. Since all validations should take place before a certain command button is clicked, the GotFocus event for the button may be used for validation code. An alternative is the Validate event. The Validate event occurs before the focus shifts to a (second) control that has its CausesValidation property set to True

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 6 Code to Search for Video by ID Number datVideos.RecordSource = "Videos" datVideos.Refresh strTarget = "ID_Num = " & txtVideoID.Text datVideos.Recordset.FindFirst strTarget If datVideos.Recordset.NoMatch Then MsgBox "Video does not exist", vbCritical, _ "Video Status" txtVideoID = "" txtVideoID.SetFocus End If

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 7 Code to Display Video Private Sub cmdCalc_GotFocus() Dim strTarget As String If txtVideoID.Text = "" Then MsgBox "You must enter a valid ID number." txtVideoID.SetFocus Exit Sub Else datVideos.RecordSource = "Videos" datVideos.Refresh strTarget = "ID_Num = " & txtVideoID.Text datVideos.Recordset.FindFirst strTarget If datVideos.Recordset.NoMatch Or _ datVideos.Recordset("Rented") Then MsgBox "Video does not exist or is rented", _ vbCritical, "Video Status" txtVideoID.Text = "" txtVideoID.SetFocus Else txtVideoName.Text = datVideos.Recordset("Video_Name") txtVideoPrice.Text = Format(datVideos.Recordset_ (“Price”),”currency") End If End Sub

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 8 Setting the RecordSource at Run Time Requires two statements—one to assign the RecordSource property to the name of a database table and one to refresh the database with the data control Refresh method: datName.RecordSource = "TableName" datName.Refresh In addition to being set equal to a database table, the RecordSource property can be set equal to an SQL query or even to a query created in Microsoft Access. Once the RecordSource property has been set with these two statements, we may work with the new Recordset.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 9 DB Controls Three useful controls for working with databases are: –DBList control (dbl) –DBCombo control (dbc) –DBGrid control (dgd) You will need to add them to the toolbox by using the Project|Components menu option.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 10 The DBGrid Control The DBGrid control can be used to display an entire table or selected rows and columns. It can also be used to dynamically edit the database by saving changes that are entered in the various cells of the control. The DBGrid control is linked to the database by setting its DataSource property equal to a data control on the same form. To prevent the user from changing the contents of DBGrid cells, set the AllowUpdate property to False.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 11 The DBList and DBCombo Controls The DBList and DBCombo controls are useful for displaying just one column of the database table for all or selected rows. They are read-only controls in that you cannot edit the database through them. The DBList has two key properties for displaying records: –The RowSource property points to the data control that will provide the database records to be listed. –The ListField property designates the database field that will be displayed.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 12 SQL Queries An SQL query may be used as the RecordSource property. The basic form of an SQL query: SELECT fieldnames FROM tables WHERE query The query part of the SQL statement looks exactly like the queries we have been using with the FindFirst and FindNext methods. For example: SELECT * FROM Members WHERE City = ’Athens’ (the asterisk is used to find all fields.)

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 13 The LIKE Operator The “LIKE” operator allows us to look for field values that partially match a search string input by the user. The query combines the LIKE operator with the asterisk wild-card character (*). The general form of the query using the LIKE Operator is: –SELECT * FROM Table WHERE FieldName LIKE ’*SearchString*’ ( both the asterisks and the search string are enclosed in apostrophes in the query string)

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 14 The SelectedItem Property The SelectedItem property of the DBList control can be used to find the bookmark in the database of a selected item. To ensure an item has been selected use the IsNull( ) function to check the SelectedItem property.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 15 More On the DB Controls The DBList (and DBCombo) control can be linked to another DB control so that the field name in the DBList control is updated by clicking a record in the other DB control. To make a link, consider three other properties: –The DataSource property is the name of the data control with the recordset to be updated. –The DataField property is the field to be updated in the changing recordset. –The BoundColumn is the name of the field with the value to be inserted in the table being updated. Note that the BoundColumn and DataField properties point to the same field in different database tables.

Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid Control DBList and DBCombo Controls SQL Queries The Data View Window Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 16 The Data View Window The Data View window allows you to view and modify a database from within Visual Basic. Click on the Data View icon in the toolbar or select Data View window from the View menu bar option. The Data Link Properties window is where you will need to set the database properties. If connection is set properly, you should be able to display Tables, Views, and Stored Procedures folders.