1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.

Slides:



Advertisements
Similar presentations
Access Manual 4 By Elham S.Khorasani Ismail Guneydas Dhawala Kovuri.
Advertisements

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Benchmark Series Microsoft Access 2010 Level 1
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
 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)
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.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
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.
Access Tutorial 1 Creating a Database
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
Chapter Extension 6 Using Microsoft Access © 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Chapter 3 Maintaining a Database
Some Basic Database Terminology
Chapter 10 - VB.Net by Schneider1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Relational Databases and SQL.
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 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
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.
Course ILT Access basics Unit objectives Define database and database-related terminology, and plan a database Start Access and open, create, view, and.
Office Management Tools II Ms Saima Gul.  When you create your tables, you should assign each table a primary key—one or more fields whose contents are.
MS-ACCESS BY SANGEETHA PARTHASARATHY Topics to be covered §Comparing Values in Selection Criteria §Calculating Values in a Query §Changing the appearance.
Relationships and Advanced Query Concepts Using Multiple Tables Please use speaker notes for additional information!
Access Manual 2 By Dhawala Kovuri Elham S.Khorasani Ismail Guneydas.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
Office Management Tools II Ms Saima Gul. Office Management Tools II Ms Saima Gul.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 8 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 8 Creating.
Ch Determine the output displayed from procedures Lab sheet 10.4.
Chapter 10 - VB.Net by Schneider1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Relational Databases and SQL.
® Microsoft Office 2013 Access Creating a Database.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 2 BACKNEXTEND 2-1 LINKS TO OBJECTIVES Creating Related Tables Creating Related Tables Determining.
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.
Databases with LINQ. LINQ to SQL LINQ to SQL uses LINQ syntax to query databases. LINQ to SQL classes are automatically generated by the IDE’s LINQ to.
Microsoft Access Lesson 2 Lexington Technology Center February 13, 2003 Bob Herring On the Web at
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.
Introduction to a Database Defining a database Database window in Access The six items in window: Tables, Queries Forms, Reports, Macros, Modules.
Ch. 101 Database Management An Introduction to Databases.
You can sort Access data so you can view records in the order you want to view them, and you can filter data so you only see the records you want to see.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
CS 281 – Fall 2015 Lab 4 Parametric Query and Forms in MS Access.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
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.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
CS 281 – Fall 2010 Lab 4 Parametric Query and Forms in MS Access.
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.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual Basic 2010 How to Program
Incorporating Databases with ADO.NET
Incorporating Databases with ADO.NET
CIS16 Application Programming with Visual Basic
Presentation transcript:

1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases

An Introduction to Databases Data Source Configuration Wizard Accessing a Database Table Binding to Additional Tables Browsing a Connected Database Querying a Table with LINQ Primary and Foreign Keys The Join of Two Tables

3 Sample Table – Cities Table

4 Sample Table – Countries Table

5 Database Terminology A table is a rectangular array of data. Each column of the table, called a field, contains the same type of information. Each row, called a record, contains all the information about one entry in the table.

6 Database Management Software (DBMS) Used to create databases Databases contain one or more related tables Examples of DBMS are Access, Oracle, and SQL Server. The databases used in this chapter are found in the folder Programs\Ch10\Databases. They were created with Access and have the extension accdb.

Megacities.accdb Contains the two tables Cities and Countries shown earlier. This database will be used extensively in the examples for this chapter. Several steps are required to bind to a table of the database. We will use the Data Source Configuration Wizard. (See the next sixteen slides.) 7

Binding to the Cities Table Add a BindingSource control to the form. (The control is in the Data and All Windows Forms group of the Toolbox. It appears in the form’s component tray with the name BindingSource1.) 8

DataSource Property of BindingSource1 9 click here

Choose Data Source Type 10 select click on Next button

Choose Database Model 11 select click on Next button

Choose Data Connection 12 click on New Connection button

Add Connection Dialog Box 13 click on Change button

Change Data Source Box 14 click on Continue button select

15 Add Connection Dialog Box click on Browse button

Select Database File 16 double-click on Megacities.accdb

Add Connection Dialog Box 17 click on OK button

Choose Data Connection 18 click on Next button

Copy File to Program 19 click on Yes button

Save to File 20 check this box click on Next button

Choose Database Objects 21 click on Finish button check on Tables box

Changes in Properties Window and Form 22

After Clicking on DataMember Down-Arrow 23 click on Cities

VB Generated Items 24 new code new icon

Binding Complete We are now bound to the Cities table via the MegacitiesDataSet and the CitiesTableAdapter. The next four slides show how to bind an additional table. 25

Connect an Additional Table Add another BindingSource control to the form. 26

Set DataSource Property 27 click on MegacitiesDataSet

Set DataMember Property 28 click on Countries

VB Generated Items 29 additional code shows in Load event procedure Me.CountriesTableAdapter.Fill(Me.MegacitiesDataSet.Countries) new icon

Example 1: Form 30 txtTotalPop

Example 1: Code Private Sub btnDisplay_Click(...) Handles _ btnDisplay.Click Dim query1 = From city In MegacitiesDataSet.Cities Where city.country = "India" Order By city.pop2010 Descending Select city.name lstOutput.DataSource = query1.ToList lstOutput.SelectedItem = Nothing 31

Example 1: Code (continued) Dim query2 = From city In _ MegacitiesDataSet.Cities Where city.country = "India" Select city.pop2010 txtTotalPop.Text = CStr(query2.Sum) End Sub 32

Example 1: Output 33

Example 2: Form 34 txtName dgvOutput

Example 2: Code Dim query = From country In _ MegacitiesDataSet.Countries Where country.name = txtName.Text Select country.name, country.pop2010, country.monetaryUnit If query.Count = 1 Then dgvOutput.DataSource = query.ToList dgvOutput.CurrentCell = Nothing Else MessageBox.Show("Country not found") End If 35

Example 2: Output 36

Example 3: Form 37 dgvOutput

Example 3: Code Dim query = From city In _ MegacitiesDataSet.Cities Let popIncrease = city.pop city.pop2010 Let formattedIncr = popIncrease.ToString("N1") Where popIncrease > 1 Order By popIncrease Descending Select city.name, formattedIncr 38

Example 3: Code (continued) dgvOutput.DataSource = query.ToList dgvOutput.CurrentCell = Nothing dgvOutput.Columns("name").HeaderText = "City" dgvOutput.Columns("formattedIncr").HeaderText = "Population Increase" 39

Example 3: Output 40

41 Primary Keys A primary key is used to uniquely identify each record. Databases of student enrollments in a college usually use a field of student ID numbers as the primary key. Why wouldn't names be a good choice as a primary key?

42 Primary Key Fields Specified when database is created. Every record must have an entry in the primary-key field. Two records cannot have the same entry in the primary-key field. This pair of requirements is called the Rule of Entity Integrity.

43 Two or More Tables When a database contains two or more tables, the tables are usually related. For instance, the two tables Cities and Countries are related by their country and name fields. Notice that every entry in Cities.country appears uniquely in Countries.name and Countries.name is a primary key. We say that Cities.country is a foreign key of Countries.name.

44 Foreign Keys Foreign keys can be specified when a table is first created. Visual Basic will insist on the Rule of Referential Integrity. This Rule says that each value in the foreign key must also appear in the primary key of the other table.

45 Join A foreign key allows Visual Basic to link (or join) two tables from a relational database When the two tables Cities and Countries from Megacities.accdb are joined based on the foreign key Cities.country, the result is the table in the next slide. The record for each city is expanded to show its country’s population and its monetary unit.

46 A Join of Two Tables

47 Beginning of Query to Join the Two Tables from Megacities Dim query = From city In _ MegacitiesDataSet.Cities Join country In MegacitiesDataSet.Countries On city.country Equals country.name

Example 6: Form 48

Example 6: Code for Load Event Me.CountriesTableAdapter.Fill(Me.MegacitiesDataSet.Countries) Me.CitiesTableAdapter.Fill(Me.MegacitiesDataSet.Cities) Dim query = From country In _ MegacitiesDataSet.Countries Order By country.monetaryUnit Ascending Select country.monetaryUnit Distinct lstCurrencies.DataSource = query.ToList 49

Example 6: Later Code Dim query = From city In _ MegacitiesDataSet.Cities Join country In MegacitiesDataSet.Countries On city.country Equals country.name Where country.monetaryUnit = lstCurrencies.Text Order By city.name Ascending Select city.name For Each city As String In query lstCities.Items.Add(city) Next 50

Example 6: Sample Output 51

Editing and Designing Databases A Program to Edit the Cities Table Designing the Form for the Table-Editing Program Writing the Table-Editing Program Principles of Database Design

Editing Program: Form 53 navigation toolbar

Navigation Toolbar 54

Editing Program: Output 55

Building the Form Start a new program and bind the Cities table. Add a BindingNavigator control (found in Data group of Toolbox) to the form. Note: BindingNavigator1 appears in component tray and a navigation toolbar appears at the top of the form. 56

Navigation Bar Added 57 button to be changed

Change Last Button 58 click here

Change Last Button (continued) 59 click on Button

Change Last Button (continued) 60 new button New button has name ToolStripButton 1 Use the Properties window for the button to change the Name, Text, and Image settings to btnUpdate, Update, and Disk.bmp.

Change Last Button (continued) 61 Disk.bmp used for picture on button

Display Data Sources Window 62 Click here

Bind Text Boxes to Cities Table Fields 63 drag these four items onto form

Text Boxes and Labels Generated by VB 64

Complete Design of Form 65

Index Numbers Each record of the table Cities has an index number ranging from 0 to 9. The value of BindingSource1.Position is the index number of the record currently displayed in the form. 66

Index Numbers (continued) The statement BindingSource1.Position = n displays the record having index number n. The value of BindingSource1.Find("name", cityName) is the index number of the specified city. 67

Principles of Database Design Data should usually be stored in their smallest parts. Avoid redundancy. Avoid tables with intentionally blank entries. Strive for table cohesion. Avoid fields whose values can be calculated from existing fields. 68