Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic 2010 5 th Edition.

Slides:



Advertisements
Similar presentations
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Advertisements

 Open the Paradise.exe file  Application displays records in the Books database  Allows the store manager to enter an author’s name (or part of a name)
Pasewark & Pasewark Microsoft Office XP: Introductory Course 1 INTRODUCTORY MICROSOFT ACCESS Lesson 4 – Finding and Ordering Data.
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.
Some Introductory Programming 1. Structured Query Language (SQL) - used for queries. - a standard database product. 2. Visual Basic for Applications -
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Access Tutorial 3 Maintaining and Querying a Database
Automating Tasks With Macros
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Querying a Database Using the Select Query Window
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Introduction To Form Builder
Concepts of Database Management Sixth Edition
1 Computing for Todays Lecture 16 Yumei Huo Fall 2006.
Microsoft Access 2010 Chapter 7 Using SQL.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Chapter 2 Querying a Database
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Maintaining and Querying a Database Microsoft Access 2010.
XP New Perspectives on Microsoft Access 2002 Tutorial 41 Microsoft Access 2002 Tutorial 4 – Creating Forms and Reports.
Databases and LINQ Visual Basic 2010 How to Program 1.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 2 Querying a Database MICROSOFT ACCESS 2010.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Creating a Web Site to Gather Data and Conduct Research.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
Microsoft Access You will need a pen/pencil.. What is Microsoft Access? Access is a database management system.  Create a database, add/change delete.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Automating Database Processing
® Microsoft Office 2010 Access Tutorial 3 Maintaining and Querying a Database.
Key Applications Module Lesson 21 — Access Essentials
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Microsoft Access 2013 ®® Tutorial 10 Automating Tasks with Macros.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Unit 5, Lesson 1 Working with Databases. Objectives Identify the parts of the Access screen. Identify the parts of the Access screen. Understand the purpose.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
® Microsoft Access 2010 Tutorial 10 Automating Tasks with Macros.
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.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload.
Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Modify Tables and FieldsModify Tables and Fields Lesson 4 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 2 ® Building Queries.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
CS 281 – Fall 2010 Lab 4 Parametric Query and Forms in MS Access.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 4 1 Microsoft Office Access 2003 Tutorial 4 – Creating Forms and Reports.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Lesson 17 Mail Merge. Overview Create a main document. Create a data source. Insert merge fields into a main document. Perform a mail merge. Use data.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Microsoft Visual Basic 2010: Reloaded Fourth Edition
CIS16 Application Programming with Visual Basic
Tutorial 10 Automating Tasks with Macros
Presentation transcript:

Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition

Programming with Microsoft Visual Basic 2010, 5 th Edition Previewing the Academy Award Winners Application 2 Open the Award.exe file Application displays records from the Movies database Movies database stores information on Academy Award winners for Best Picture Movie title Year Name of production company Application allows user to add or delete database records

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure 14-1 Academy Award Winners application 3

Programming with Microsoft Visual Basic 2010, 5 th Edition Previewing the Academy Award Winners Application (cont’d.) 4 Add missing record to database Click Year won text box In Add new record section of the interface Type 2002 Enter Chicago as movie name Enter Miramax as production company Click the Add button

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure 14-2 Result of adding the missing record 5

Programming with Microsoft Visual Basic 2010, 5 th Edition Previewing the Academy Award Winners Application (cont’d.) 6 Delete the record from the database Click 2002 in first column of DataGridView control Click the Delete button Click Yes to confirm the deletion

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson A Objectives 7 After studying Lesson A, you should be able to: Add records to a dataset Delete records from a dataset Sort the records in a dataset

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset 8 Add and delete records: Without using a BindingNavigator control Microsoft database is stored in Movies.accdb file Contains one table, tblMovies Contains nine records, each with three fields YearWon field is numeric Title field contains text ProductionCo field contains text

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset (cont’d.) 9 Figure 14-3 Data contained in the tblMovies table

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset (cont’d.) 10 Figure 14-4 Interface for the Academy Award Winners application

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset (cont’d.) 11 Figure 14-5 Records displayed in the TblMoviesDataGridView control

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset (cont’d.) 12 Figure 14-6 Syntax and examples of adding a record to a dataset

Programming with Microsoft Visual Basic 2010, 5 th Edition Adding Records to a Dataset (cont’d.) 13 TableAdapter object’s Update method Used to save the changes to the database associated with the dataset Good practice: Place Update method within the Try block of a Try….Catch statement Because errors can occur when saving data

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure 14-8 Syntax and examples of saving dataset changes to a database (continues) 14

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure 14-8 Syntax and examples of saving dataset changes to a database (cont’d.) 15

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure 14-9 Add button’s Click event procedure 16

Programming with Microsoft Visual Basic 2010, 5 th Edition Sorting the Records in a Dataset 17 BindingSource object’s Sort method Used to sort records To have records sorted when application is started: Place Sort method in the form’s Load event procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Syntax and examples of sorting the records in a dataset 18

Programming with Microsoft Visual Basic 2010, 5 th Edition Deleting Records from a Dataset 19 Code Delete button’s Click event procedure Deletes record whose YearWon field contains the value entered in the txtDeleteYear control Before deleting record, display a message that asks user for confirmation Use MessageBox.Show method

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure MessageBox.Show method entered in the btnDelete control’s Click event procedure 20

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Syntax and examples of locating a record in a dataset 21

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Syntax and an example of deleting a record from a dataset 22

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Additional code entered in the btnDelete control’s Click event procedure 23

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson A Summary 24 To add a record to a dataset, use the syntax: dataSetName.tableName.AddtableRow(valueField1[, valueField2…, valueFieldN]) Use the TableAdapter object’s Update method to save dataset changes to a database Use the BindingSource object’s Sort method to sort the records in a dataset To locate a record in a dataset, use the syntax: dataRowVariable=dataSetName.tableName.FindByfie ldName(value)

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson A Summary (cont’d.) 25 Use the DataRow variable’s Delete method to delete a record from a dataset

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson B Objectives 26 After studying Lesson B, you should be able to: Query a database using the SQL SELECT statement Create queries using the Query Builder dialog box

Programming with Microsoft Visual Basic 2010, 5 th Edition Structured Query Language 27 SQL (Structured Query Language) Set of statements to perform common database tasks Examples: Storing, retrieving, updating, deleting, and sorting data Can be used with a variety of database management systems and computers of all sizes

Programming with Microsoft Visual Basic 2010, 5 th Edition The SELECT Statement 28 Most commonly used statement in SQL Allows you to specify fields and records you want to view Can control the order in which records appear when displayed WHERE and ORDER BY clauses Optional parts of the syntax WHERE is used to limit records displayed ORDER BY is used to sort records

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Syntax and examples of the SELECT statement (continues) 29

Programming with Microsoft Visual Basic 2010, 5 th Edition Figure Syntax and examples of the SELECT statement (cont’d.) 30

Programming with Microsoft Visual Basic 2010, 5 th Edition Creating a Query 31 Open the DataSet Designer window Point to Add on the shortcut menu and click Query Choose SQL statements as the Command type Choose a Query Type Two ways to build a query using the SELECT statement Type the statement yourself Or use the Query Builder button Opens the Query Builder dialog box

Programming with Microsoft Visual Basic 2010, 5 th Edition Creating a Query (cont’d.) 32 Figure DataSet Designer window

Programming with Microsoft Visual Basic 2010, 5 th Edition Creating a Query (cont’d.) 33 Figure Choose a Command Type screen in the TableAdapter Query Configuration Wizard

Programming with Microsoft Visual Basic 2010, 5 th Edition Creating a Query (cont’d.) 34 Figure Choose a Query Type screen

Programming with Microsoft Visual Basic 2010, 5 th Edition 35 Figure Specify a SQL SELECT statement screen

Programming with Microsoft Visual Basic 2010, 5 th Edition 36 Figure Query Builder dialog box

Programming with Microsoft Visual Basic 2010, 5 th Edition Creating a Query (cont’d.) 37 Click Execute Query button to run query Results appear in the Results pane Create query to select all fields for records from year 2006 and later

Programming with Microsoft Visual Basic 2010, 5 th Edition 38 Figure SELECT statement containing a WHERE clause

Programming with Microsoft Visual Basic 2010, 5 th Edition 39 Figure Records displayed in ascending order by the Title field

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson B Summary 40 The SELECT statement is used to query a database using SQL The SELECT statement’s WHERE clause limits the records displayed The SELECT statement’s ORDER BY clause sorts the selected records in a specified order To open the DataSet Designer window: Open the dataset’s schema file (.xsd)

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson B Summary (cont’d.) 41 To start the TableAdapter Query Configuration Wizard: Right-click table adapter’s name in DataSet Designer window Point to add on shortcut menu and click Query To open the Query Builder dialog box: Use TableAdapter Query Configuration Wizard Specify a SQL SELECT statement screen Then click Query Builder button The % wildcard is used to represent characters in the WHERE clause’s condition

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson C Objectives 42 After studying Lesson C, you should be able to: Create a parameter query Save a query Invoke a query from code Add records to a dataset using the SQL INSERT statement Delete records from a dataset using the SQL DELETE statement

Programming with Microsoft Visual Basic 2010, 5 th Edition Parameter Queries 43 Parameter marker A question mark (?) Used in a parameter query Allows user to specify query parameters

Programming with Microsoft Visual Basic 2010, 5 th Edition Parameter Queries (cont’d.) 44 Figure Examples of parameter queries

Programming with Microsoft Visual Basic 2010, 5 th Edition Parameter Queries (cont’d.) 45 Test SELECT statements from Figure Right-click MoviesDataSet.xsd Then click Open to open DataSet Designer window Start the TableAdapter Query Configuration Wizard Use Query Builder dialog to create a query that selects only the Chicago record Execute query Type Chicago in the Value column of the Query Parameters dialog box

Programming with Microsoft Visual Basic 2010, 5 th Edition 46 Figure Query Parameters dialog box

Programming with Microsoft Visual Basic 2010, 5 th Edition Saving a Query 47 For an application to use a query during run time: Must save query and invoke it from code Use the TableAdapter Query Configuration Wizard Save a query that contains SELECT statement Associate the query with one or more methods

Programming with Microsoft Visual Basic 2010, 5 th Edition 48 Figure Default query in the Specify a SQL SELECT statement screen Figure Parameter query in the Specify a SQL SELECT statement screen

Programming with Microsoft Visual Basic 2010, 5 th Edition 49 Figure Completed Choose Methods to Generate screen

Programming with Microsoft Visual Basic 2010, 5 th Edition 50 Figure Wizard Results screen Figure Method names included in the DataSet Designer window

Programming with Microsoft Visual Basic 2010, 5 th Edition Invoking a Query from Code 51 Methods associated with a query Can be used to invoke query during run time Next example Enter appropriate methods in Display button’s Click event procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition Invoking a Query from Code (cont’d.) 52 Figure If clause and Fill method entered in the procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition Invoking a Query from Code (cont’d.) 53 Figure Display button’s Click event procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition The INSERT and DELETE Statements 54 INSERT statement Used to insert records in a database DELETE statement Used to delete records from a database Both statements can be used in a query Known as Insert query and Delete query

Programming with Microsoft Visual Basic 2010, 5 th Edition 55 Figure Syntax and examples of the SQL INSERT statement

Programming with Microsoft Visual Basic 2010, 5 th Edition 56 Figure Syntax and examples of the SQL DELETE statement

Programming with Microsoft Visual Basic 2010, 5 th Edition The INSERT and DELETE Statements (cont’d.) 57 Create an insert query Start the TableAdapter Query Configuration Wizard Verify Use SQL statements radio button is selected Click INSERT radio button On Choose a Query Type screen Default INSERT statement appears Change the function’s name

Programming with Microsoft Visual Basic 2010, 5 th Edition 58 Figure Choose Function Name screen Figure Default INSERT statement for the tblMovies table

Programming with Microsoft Visual Basic 2010, 5 th Edition 59 Figure InsertRecordQuery function Figure Wizard Results screen

Programming with Microsoft Visual Basic 2010, 5 th Edition The INSERT and DELETE Statements (cont’d.) 60 Create a delete query Start the TableAdapter Query Configuration Wizard Click DELETE radio button On Choose a Query Type screen Default DELETE statement appears Change the function’s name

Programming with Microsoft Visual Basic 2010, 5 th Edition 61 Figure DeleteRecordQuery function Figure SQL DELETE statement

Programming with Microsoft Visual Basic 2010, 5 th Edition The INSERT and DELETE Statements (cont’d.) 62 Code Click event procedures for Add and Delete buttons Add button uses InsertRecordQuery function Delete button uses DeleteRecordQuery function Test the Add and Delete buttons

Programming with Microsoft Visual Basic 2010, 5 th Edition 63 Figure Selection structure entered in the btnDelete control’s Click event procedure Figure Additional lines of code entered in the btnAdd_Click procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition 64 Figure Nested selection structure entered in the procedure Figure Additional lines of code entered in the btnDelete_Click procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson C Summary 65 Parameter query Created using a question mark in place of the criteria’s value in the WHERE clause The TableAdapter Query Configuration Wizard Can be used to save a query that contains the SELECT statement Can be used to associate a query containing the INSERT or DELETE statement with a function To invoke a query from code: Enter the query’s method or function in a procedure

Programming with Microsoft Visual Basic 2010, 5 th Edition Lesson C Summary (cont’d.) 66 The INSERT statement inserts records into a database The DELETE statement deletes records from a database