© 1999, by Que Education and Training, Chapter 11, pages 593-625 of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

© 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 10 – Designing.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
Using Visual Basic 6.0 to Create Web-Based Database Applications
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)
Using the Data Access Controls: DAO & ADO Presented by Victor Matos.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
Chapter 8 Relational Databases ActiveX Database Controls 8 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Microsoft Access Ervin Ha.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Resources – MS Access Free Online Training Resources  Using an Access database to store and information (2 min)
Chapter 10 - VB.Net by Schneider1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Relational Databases and SQL.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
ASP.NET Programming with C# and SQL Server First Edition
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Handling of data from multiple databases. Visual Basic Database Visual Basic application acts as a front-end to the database Visual Basic application.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
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.
Using Visual Basic 6.0 to Create Web-Based Database Applications
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
Copyright © 2001 by Wiley. All rights reserved. Chapter 9: Introduction to Working with Databases in Visual Basic Database Concepts Relational Database.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
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.
Relational Databases Database Driven Applications Retrieving Data Changing Data Analysing Data What is a DBMS An application that holds the data manages.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Concepts of Database Management Seventh Edition
How to Connect to Database ODBC (Open Database Connectivity) ADO (ActiveX Data Object) ASP Code To Connect to Database Recordset Object Navigating through.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
VB for applications. Lesson Plan Fundamentals of VB VB for handling events in Access.
AVCE ICT – Unit 7 - Programming Session 16 – Database and VB.
Introduction to Access Chapter 13 pages 1-4. What is a database??? Related information is stored in databases  All SC student information is stored in.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Using a Database Access97 Please use speaker notes for additional information!
Form and Graphical User Interfaces. Lesson plan More about queries More about entering data into a table Form.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
ADO & Recordsets. ADO Description & History  ActiveX Data Objects  History  1991 ODBC  Data Access Objects (DAO) for VB developers (JET)  Remote.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Lecture 4 Manipulating Form Data using methods of Recordset and RecordsetClone in VBA Restrict data with filter 1 Rapid Application Development.
Introduction to Databases Queries CS 146. Sample Database: CANDY_CUSTOMER CANDY_PURCHASE CANDY_CUST_TYPE CANDY_PRODUCT.
Introduction to Database Programming with Python Gary Stewart
ASP.NET Programming with C# and SQL Server First Edition
Visual Basic Database Access
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Query Methods Simple SQL Statements Start ….
 2012 Pearson Education, Inc. All rights reserved.
Database vs. DBMS Database Database Management System
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
CIS16 Application Programming with Visual Basic
Chapter 22 - SQL, MySQL, DBI and ADO
Introduction To Structured Query Language (SQL)
Introduction To Structured Query Language (SQL)
Working With Databases
Database Connections.
Updating Databases With Open SQL
Updating Databases With Open SQL
Unit – V Data Controls.
Presentation transcript:

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Structured Query Language n Also known as SQL i Industry standard for accessing relational databases n General format of SQL Select Select [Distinct] fieldlist From tablenames [Where search conditions] [Group By fieldlist] [Having group criterion] [Order By fieldlist [ASC|DESC]] n Examples Select * From Contacts Select * From Contacts, ContactTypes Where Contacts.ContactTypeID = ContactTypes.ContactTypeID Order By LastName

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Creating a new Dynaset n Steps to define new dynaset via data control 1)Set data control’s RecordSource property to SQL query 2)Re-open recordset using Refresh method n Example stSQL = “Select * From Contacts, ContactTypes Where “ _ & “Contacts.ContactTypeID = ContactTypes.ContactTypeID ” datBooks.RecordSource = stSQL datBooks.Refresh

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Database Objects n Data Access Objects (DAO) i Uses Jet DB engine to access databases n Remote Data Objects (RDO) i Used when developing client/server application that access remote ODBC database system i Requires Enterprise edition of VB & 32-bit OS n ActiveX Data Objects (ADO) i New model with VB 6.0 i Combines best features of DAO and ADO i Not limited to relational DBs i Requires OLE database driver to use with Jet DB

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach DAO Model

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Data Control vs. DAO Notation

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Options with SQL Select n Like operator i Relational operator used to find similar matches i Expression being compared is surrounded by single quotes and normally contains * wildcard u FirstName Like ‘A*’ –returns all records whose FirstName values start with A n Aggregate Queries i Used to get summary-type information i Define new field to hold the result from an aggregate function n Inner Joins

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Aggregate Queries SELECT AggFunction(fieldname) As newdbfield FROM tablename [WHERE searchcriteria]

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Inner Joins for Multiple Tables SELECT [DISTINCT] fieldlist FROM table1 INNER JOIN table2 ON table1.field1 = table2.field2 [WHERE searchcriteria] [ORDER BY fieldname] n Example Select * From Contacts INNER JOIN ContactTypes On Contacts.ContactTypeID = ContactTypes.ContactTypeID Order By LastName

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Modifying DB Records n Define action query i INSERT INTO i UPDATE i DELETE n Use Execute method i Call DBObject.Execute(stSQL)

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Example: Add a new record Private Sub WriteToDB() Dim SQL As String SQL = "INSERT INTO Employee " SQL = SQL & "(EmpName, BirthDate, PayRate, Manager)" SQL = SQL & " VALUES (" SQL = SQL & DBTextFmt(txtEmpName.Text) & ", " SQL = SQL & CStr(DBDateFmt(txtBirthdate)) & ", " SQL = SQL & txtPayRate.Text & ", " SQL = SQL & txtMgr.Text & ")" Call fEmpDB.Execute(SQL) ' Enable navigation buttons cmdFirst.Enabled = True cmdLast.Enabled = True cmdNext.Enabled = True cmdPrevious.Enabled = True End Sub

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Example: Delete a record Private Sub cmdDelete_Click() Dim SQL As String SQL = "DELETE FROM Employee Where EmpID = " & _ fEmpRS("EmpID") Call fEmpDB.Execute(SQL) Call fEmpRS.Close Call fEmpDB.Close Call ReOpenDB End Sub

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Example: Create New Database Option Explicit Private fUserWS As Workspace Private fNewDB As Database Private Sub CreateDB() Dim FileName As String Set fUserWS = DBEngine.Workspace(0) FileName = AppendFileToPath(App.Path, “NewTestDB.mdb”) If FileExists(FileName) Then If MsgBox(“The database exists. Do you want to replace it?”, _ vbYesNo + vbQuestion) = vbYes Then Kill FileName Else Exit Sub ' Do not create the DB-already exists End If Set fNewDB = fUserWS.CreateDatabase(FileName, dbLangGeneral) End Sub

© 1999, by Que Education and Training, Chapter 11, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach Example: Create Database Table ‘ Create table SQL = "CREATE TABLE Employee (" & _ "EmpID COUNTER, " & _ "EmpName TEXT(30), " & _ "BirthDate DATETIME, " & _ "PayRate CURRENCY, " & _ "Manager BIT)" Call fNewDB.Execute(SQL) ‘ Create index to improve performance SQL = "CREATE UNIQUE INDEX indEmpPrimary" SQL = SQL & " ON Employee (EmpID)" SQL = SQL & " WITH PRIMARY" Call fDBPaychecks.Execute(SQL)