Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Binding to ListBox and ComboBox Controls List and combo boxes are frequently.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Working With Databases
Computer Concepts BASICS 4th Edition
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 14.3 LINQ to SQL Programming in Visual Basic 2010: The Very Beginner’s Guide by Jim McKeown Databases – Part 3.
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.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
Copyright © 2014 Pearson Education, Inc. Chapter 10 Working with Databases.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Some Basic Database Terminology
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Databases and LINQ Visual Basic 2010 How to Program 1.
BIS121 IT for Business Application Lecture 8 – Database (Part I)
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 13 Database Management Systems: Getting Data Together.
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall1 Exploring Microsoft Office Access Committed to Shaping the Next Generation.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 10 Working with Databases.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 15: Using LINQ to Access Data in C# Programs.
Advanced Visual Basic th Edition Chapter 3: Using SQL Server Databases (c) 2007 Pearson Education Inc. All rights reserved. You may modify and copy.
Copyright © 2012 Pearson Education, Inc. Chapter 11 Databases.
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.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Thirteen Working with Access Databases and LINQ.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Copyright 2008 McGraw-Hill Ryerson 1 TECHNOLOGY PLUG-IN T7 PROBLEM SOLVING USING ACCESS.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
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.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
T7-1 LEARNING OUTCOMES – ACCESS PROBLEM SOLVING 1.Describe the process of using the Simple Query Wizard using Access 2.Describe the process of using the.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Copyright © 2014 Pearson Education, Inc. Chapter 10 Working with Databases.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
Copyright Scott-Jones Publishing, All rights reserved.
Visual Basic 2010 How to Program
4: DataGrid, DataView, and ListView
Basic select statement
Database Queries.
Brief description on how to navigate within this presentation (ppt)
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
CIS16 Application Programming with Visual Basic
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Working with Databases
Introduction to LINQ Chapter 11.
Database Applications
Chapter 10 Accessing Database Files
Presentation transcript:

Chapter 9 Working with Databases

Copyright © 2011 Pearson Addison-Wesley Binding to ListBox and ComboBox Controls List and combo boxes are frequently used to supply a list of items for a user to select from Such lists are often populated from a table Must set two list/combo box properties – The DataSource property identifies a table within a dataset – The DisplayMember property identifies the table column to be displayed in the list/combo box If table column dragged onto a list/combo box – Visual Studio creates the required dataset, table adapter, and binding source components Chapter 10 – Slide 2

Copyright © 2011 Pearson Addison-Wesley Using Loops with DataTables A For Each statement can be used to iterate over the rows collection of a table Usually, it is best to create a strongly typed row that matches the type of rows in the table For example: – Total the Amount column of PaymentsDataSet dataset Chapter 10 – Slide 3 Dim row As PaymentsDataSet.PaymentsRow Dim decTotal As Decimal = 0 For Each row In Me.PaymentsDataSet.Payments.Rows decTotal += row.Amount Next

Copyright © 2011 Pearson Addison-Wesley Structured Query Language (SQL) SQL stands for Structured Query Language – A standard language for working with database management systems – Standardized by the American National Standards Institute (ANSI) – The language of choice for interacting with database management systems Consists of a limited set of keywords – Keywords construct statements called database queries – Queries are submitted to the DBMS – In response to queries, the DBMS carries out operations on its data Chapter 10 – Slide 4

Copyright © 2011 Pearson Addison-Wesley SELECT Statement The SELECT statement retrieves data from a database – Used to select rows, columns, and tables – The most basic format for a single table is: – ColumnList must contain table column names separated by commas – The following statement selects the ID and Salary columns from the SalesStaff table: Chapter 10 – Slide 5 SELECT ColumnList FROM Table SELECT ID, Salary FROM SalesStaff

Copyright © 2011 Pearson Addison-Wesley SQL Statements and Style There is no required formatting or capitalization of SQL statements – The following queries are equivalent: – As a matter of style and readability – You should try to use consistent capitalization Chapter 10 – Slide 6 SELECT ID, Salary FROM SalesStaff select ID, Salary from SalesStaff Select id, salary from salesstaff SeLeCt Id, SaLaRy FrOm SaLeSsTaFf

Copyright © 2011 Pearson Addison-Wesley SELECT Statement Field names that contain embedded spaces must be surrounded by square brackets – For example: The * character in the column list selects all the columns from a table – For example: Chapter 10 – Slide 7 SELECT [Last Name], [First Name] FROM Employees SELECT * FROM SalesStaff

Copyright © 2011 Pearson Addison-Wesley Aliases for Column Names Column names can be renamed using the AS keyword – The new column name is called an alias – For example: Renaming columns is useful for two reasons: 1.You can hide the real column names from users for security purposes 2.You can rename database columns to make user friendly column headings in reports Chapter 10 – Slide 8 SELECT Last_Name, Hire_Date AS Date_Hired FROM SalesStaff

Copyright © 2011 Pearson Addison-Wesley Calculated Columns You can create new columns from calculated column values – For example, the following query: Multiplies the values of two columns – hoursWorked and hourlyRate Displays the result as a new column (alias) – payAmount Chapter 10 – Slide 9 SELECT employeeId, hoursWorked * hourlyRate AS payAmount FROM PayRoll

Copyright © 2011 Pearson Addison-Wesley Modifying the Query in a Data Source Dataset schema file contains an SQL query – Created as part of schema file – Named Fill, GetData() by default Right-click title bar of TableAdapter in schema – Click Configure from pop-up – Use Configuration Wizard to change simple queries – Query Builder often used for complex queries Chapter 10 – Slide 10

Copyright © 2011 Pearson Addison-Wesley Query Builder Visual Studio tool to work with SQL queries Consists of four sections called panes – The Diagram pane displays tables – The Grid pane (Criteria pane)displays query in spreadsheet form – The SQL pane shows actual SQL created – The Results pane shows data returned by query Chapter 10 – Slide 11

Copyright © 2011 Pearson Addison-Wesley Example Query Builder Window Chapter 10 – Slide 12

Copyright © 2011 Pearson Addison-Wesley Adding a Query to a TableAdapter Can add a new query as well as changing an existing one – Right-click the TableAdapter icon in component tray – Select Add Query – The Search Criteria Builder window appears Add WHERE clause to the SELECT statement – Select the New query name to enter a name for query Chapter 10 – Slide 13

Copyright © 2011 Pearson Addison-Wesley Example Search Criteria Builder Window Chapter 10 – Slide 14

Section 10.6 FOCUS ON PROBLEM SOLVING: KARATE SCHOOL MANAGEMENT APPLICATION Develop the Karate School Management Application

Copyright © 2011 Pearson Addison-Wesley Karate School Manager Startup Form Menu Selections: – File Exit – Membership List All Find member Add new member – Payments All members One member Chapter 10 – Slide 16

Copyright © 2011 Pearson Addison-Wesley All Members Form Chapter 10 – Slide 17

Copyright © 2011 Pearson Addison-Wesley Find Member by Last Name Form Chapter 10 – Slide 18

Copyright © 2011 Pearson Addison-Wesley Add New Member Form Chapter 10 – Slide 19

Copyright © 2011 Pearson Addison-Wesley Payment Form Chapter 10 – Slide 20

Section 10.7 INTRODUCTION TO LINQ LINQ (Language Integrated Query) is a query language that is built into Visual Basic and can be used to query data from many sources other than databases.

Copyright © 2011 Pearson Addison-Wesley LINQ SQL allows you to query the data in a database. LINQ allows you to query data from many other sources. LINQ is built into Visual Basic. Chapter 10 – Slide 22

Copyright © 2011 Pearson Addison-Wesley Using LINQ to Query an Array Suppose we have the following array: The following statement uses LINQ to query the array for all values greater than 100: Chapter 10 – Slide 23 Dim intNumbers() As Integer = {4, 104, 2, 102, 1, 101, 3, 103} From item In intNumbers Where item > 100 Select item

Copyright © 2011 Pearson Addison-Wesley Using LINQ to Add Query Results to a ListBox We can add the results to a ListBox Chapter 10 – Slide 24 ' Create an array of integers. Dim intNumbers() As Integer = {4, 104, 2, 102, 1, 101, 3, 103} ' Use LINQ to query the array for all numbers ' that are greater than 100. Dim queryResults = From item In intNumbers Where item > 100 Select item ' Add the query results to the list box. For Each intNum As Integer In queryResults lstResults.Items.Add(intNum) Next

Copyright © 2011 Pearson Addison-Wesley Sorting the Results of a LINQ Query Sort in ascending order: Sort in descending order: Chapter 10 – Slide 25 Dim queryResults = From item In intNumbers Where item > 100 Select item Order By item Dim queryResults = From item In intNumbers Where item > 100 Select item Order By item Descending

Copyright © 2011 Pearson Addison-Wesley Using LINQ to Add Query Results to a ListBox We can add the results to a ListBox Chapter 10 – Slide 26 ' Create an array of integers. Dim intNumbers() As Integer = {4, 104, 2, 102, 1, 101, 3, 103} ' Use LINQ to query the array for all numbers ' that are greater than 100. Dim queryResults = From item In intNumbers Where item > 100 Select item ' Add the query results to the list box. For Each intNum As Integer In queryResults lstResults.Items.Add(intNum) Next

Copyright © 2011 Pearson Addison-Wesley Sorting the Results of a LINQ Query Sort in ascending order: Sort in descending order: Chapter 10 – Slide 27 Dim queryResults = From item In intNumbers Where item > 100 Select item Order By item Dim queryResults = From item In intNumbers Where item > 100 Select item Order By item Descending

Copyright © 2011 Pearson Addison-Wesley More About LINQ LINQ uses operators that are similar to SQL Unlike SQL, LINQ is built into Visual Basic Queries are written directly into the program – VB compiler checks the syntax of the query – Immediately displays LINQ mistakes LINQ can be used to query any data that is stored in memory as an object Chapter 10 – Slide 28