Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

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)
BIM211 – Visual Programming Database Operations 1.
BIM313 – Advanced Programming Database Operations 1.
Chapter 14.3 LINQ to SQL Programming in Visual Basic 2010: The Very Beginner’s Guide by Jim McKeown Databases – Part 3.
1 Web-Enabled Decision Support Systems Database Connectivity with ADO.NET Prof. Name Position (123) University Name.
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.
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
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.
Access Tutorial 1 Creating a Database
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Chapter 7: Sub and Function Procedures
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Some Basic Database Terminology
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
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.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
CHAPTER EIGHT Accessing Data Processing Databases.
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.
Key Applications Module Lesson 21 — Access Essentials
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
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.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
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.
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 ADO.Net and VS Database Tools and Data Binding ISYS 350.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Ch. 101 Database Management An Introduction to Databases.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
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.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 25 I’m Suffering from Information Overload.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
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.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
1 Access Lesson 1 Understanding Access Fundamentals Microsoft Office 2010 Fundamentals Story / Walls.
Creating SQL Database file And Displaying a Database Table in a DataGridView.
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.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Visual Basic 2010 How to Program
Brief description on how to navigate within this presentation (ppt)
CIS16 Application Programming with Visual Basic
CIS16 Application Programming with Visual Basic
Database Applications
Chapter 10 Accessing Database Files
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition

2 Databases Lesson A Objectives Define the terms used when talking about databases Connect an application to a database Bind table and field objects to controls Explain the purpose of the DataSet, BindingSource, TableAdapter, and BindingNavigator objects

3 Programming with Microsoft Visual Basic 2005, Third Edition Databases Lesson A Objectives (continued) Access the records in a dataset Move the record pointer

4 Programming with Microsoft Visual Basic 2005, Third Edition Previewing the Trivia Game Application Go to Run command on Windows Start menu Browse to the VB2005\Chap12 folder Open the Trivia Game.exe file Trivia Game application user interface appears

5 Programming with Microsoft Visual Basic 2005, Third Edition Previewing the Trivia Game Application (continued) Figure 12-1: Trivia Game application

6 Programming with Microsoft Visual Basic 2005, Third Edition Database Terminology Database: organized collection of related information Relational database –Database that stores information in tables –Each column in a table represents a field –Each row in a table represents a record Primary key: field uniquely identifying a record A two-table database has parent and child tables Foreign key: links child record to parent record

7 Programming with Microsoft Visual Basic 2005, Third Edition Database Terminology (continued) Figure 12-2: Example of a one-table relational database

8 Programming with Microsoft Visual Basic 2005, Third Edition Database Terminology (continued) Figure 12-3: Example of a two-table relational database

9 Programming with Microsoft Visual Basic 2005, Third Edition ADO.NET 2.0 ADO (ActiveX Data Objects).Net 2.0 technology –Connects an application to a database –Allows application to read from and write to database –Connection is closed after dataset is copied or saved Dataset: copy of records application wants to access Opening Employees.mdf in IDE window –Connect the database to an application –Right-click table’s name in Server Explorer window –Click Show Table Data

10 Programming with Microsoft Visual Basic 2005, Third Edition ADO.NET (continued) Figure 12-4: Data contained in the tblEmploy table

11 Programming with Microsoft Visual Basic 2005, Third Edition Connecting an Application to a Database Create a database connection to access data Data Source Configuration Wizard –Helps you connect an application to a database

12 Programming with Microsoft Visual Basic 2005, Third Edition Connecting an Application to a Database (continued) Figure 12-5: Procedure for connecting an application to a database

13 Programming with Microsoft Visual Basic 2005, Third Edition Connecting an Application to a Database (continued) Figure 12-12: EmployeesDataSet added to the Data Sources window

14 Programming with Microsoft Visual Basic 2005, Third Edition Previewing the Data Contained in a Dataset Right-click the Data Sources window Click Preview Data to open Preview Data dialog box Select the object to preview, then click Preview After previewing the data, click the Close button

15 Programming with Microsoft Visual Basic 2005, Third Edition Previewing the Data Contained in a Dataset (continued) Figure 12-14: Data displayed in the Preview Data dialog box

16 Programming with Microsoft Visual Basic 2005, Third Edition Binding the Objects in a Dataset Bind dataset objects before viewing contents Binding: connecting a dataset object to a control Bound controls: the connected controls Types of controls used to bind dataset objects –Computer-created control –Existing control

17 Programming with Microsoft Visual Basic 2005, Third Edition Binding the Objects in a Dataset (continued) Figure 12-15: Ways to bind the objects in a dataset

18 Programming with Microsoft Visual Basic 2005, Third Edition Having the Computer Create a Bound Control Impact of dragging dataset object to form –Computer creates control (indicated by icon) –Dataset object is automatically bound to control Example –Drag tblEmployee table object to form –DataGridView control displays tabular data –Rows represent records, columns represent fields Use list arrow to change control linked to object

19 Programming with Microsoft Visual Basic 2005, Third Edition Having the Computer Create a Bound Control (continued) Figure 12-17: Result of clicking the tblEmploy table object’s list arrow

20 Programming with Microsoft Visual Basic 2005, Third Edition Having the Computer Create a Bound Control (continued) Figure 12-20: Illustration of the relationships among the database, the objects in the component tray, and the controls on the form

21 Programming with Microsoft Visual Basic 2005, Third Edition The Copy to Output Directory Property Determines the way a file is handled in application Copy always –Default setting of Copy to Output Directory property –Database file copied to project’s bin\Debug folder –Result:.mdf file appears in two different folders –Changes to file in bin\Debug folder are overwritten Copy if newer –Set this property to preserve run-time changes –Copies over file in bin\Debug only if file is not current

22 Programming with Microsoft Visual Basic 2005, Third Edition Binding to an Existing Control Method 1 –Drag object from Data Sources window to control Method 2 –Click the control –Set one or more properties in the Properties window Properties to set depends on control being bound –DataGrid: set DataSource and DataMember –ListBox: set DataSource and DisplayMember

23 Programming with Microsoft Visual Basic 2005, Third Edition Binding to an Existing Control (continued) Figure 12-23: Result of dragging the field objects to the existing label controls

24 Programming with Microsoft Visual Basic 2005, Third Edition Accessing the Records in a Dataset BindingSource object’s Position property –Stores an invisible record pointer –Positions are integer values  = 0 Syntax: bindingSourceName.Position Example –Me.TblEmployBindingSource.Position = 4 –Moves record pointer to fifth record in the dataset BindingSource object’s Move methods –Also used to move the record pointer in a dataset

25 Programming with Microsoft Visual Basic 2005, Third Edition Accessing the Records in a Dataset (continued) Figure 12-25: Syntax and examples of the BindingSource object’s Move methods

26 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson A A relational database stores information in tables Tables comprise rows (records) and columns (fields) Two-table database comprises parent and child tables Two types of id fields: primary key and foreign key Relational database is stored as a file on disk

27 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson A (continued) ADO.NET 2.0 connects application to database Dataset: copies of records from database stored in main memory To view dataset objects, they must be bound to a control Use BindingSource object’s Position property or its Move methods to move the record pointer

28 Programming with Microsoft Visual Basic 2005, Third Edition Creating Queries Lesson B Objectives Write SQL SELECT statements Create a query using the Query Configuration Wizard Associate a ToolStrip control with a query

29 Programming with Microsoft Visual Basic 2005, Third Edition The DataSet Designer Browse to VB2005\Chap12 folder Copy Morgan Industries Solution-DataGrid folder Rename copy as follows: –Morgan Industries Solution-DataGrid-Query Open new file in Visual Studio 2005

30 Programming with Microsoft Visual Basic 2005, Third Edition The DataSet Designer (continued) Figure 12-26: Data displayed in the TblEmployDataGridView control

31 Programming with Microsoft Visual Basic 2005, Third Edition The DataSet Designer (continued) DataSet Designer controls the display of data –Shows name of table and field objects for dataset –Also shows the name of TableAdapter object TableAdapter object: queries underlying database Query: specifies fields and records to retrieve DataSet Designer puts.xsd file in Solution Explorer.xsd extension indicates XML schema definition file –XML (extensible markup language) –.xsd file type defines tables and fields for a dataset

32 Programming with Microsoft Visual Basic 2005, Third Edition The DataSet Designer (continued) Figure 12-27: Three ways to open the DataSet Designer

33 Programming with Microsoft Visual Basic 2005, Third Edition The Dataset Designer (continued) Figure 12-28: DataSet Designer

34 Programming with Microsoft Visual Basic 2005, Third Edition Structured Query Language Structured Query Language (SQL) –Access/manipulate data stored in databases –Organized as a set of commands Database tasks performed with SQL commands –Storing, retrieving, updating, deleting, and sorting SELECT statement –Most commonly used command in SQL –Specifies the fields and records you want to view –Refine query with WHERE and/or ORDER BY clause

35 Programming with Microsoft Visual Basic 2005, Third Edition Structured Query Language (continued) Figure 12-30: Syntax and examples of the SELECT statement (continued)

36 Programming with Microsoft Visual Basic 2005, Third Edition Structured Query Language (continued) Figure 12-30: Syntax and examples of the SELECT statement

37 Programming with Microsoft Visual Basic 2005, Third Edition Creating a New Query Use TableAdapter Query Configuration Wizard

38 Programming with Microsoft Visual Basic 2005, Third Edition Creating a New Query (continued) Figure 12-31: Procedure for creating a query using the TableAdapter Query Configuration Wizard

39 Programming with Microsoft Visual Basic 2005, Third Edition Creating a New Query (continued) Figure 12-38: SELECT statement containing the WHERE and ORDER BY clauses

40 Programming with Microsoft Visual Basic 2005, Third Edition Allowing the User to Run a Query ToolStrip control –Allows a user to run a query at runtime How to add query feature –Right-click the name of the TableAdapter object –Click Add Query to open Search Criteria Builder dialog –Select the Existing query name radio button –Click the down arrow in list box next to radio button –Click the name of the query in the list –Click OK button to close Search Criteria Builder dialog

41 Programming with Microsoft Visual Basic 2005, Third Edition Allowing the User to Run a Query (continued) Figure 12-44: ToolStrip control and object added to the application

42 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson B DataSet Designer: used to control the display of fields and records from a database TableAdapter object: connects dataset to underlying database using queries Query: specifies fields and records to retrieve from a database Structured Query Language (SQL): set of commands used to access and manipulate data in a database Select statement: specifies fields/records to view

43 Programming with Microsoft Visual Basic 2005, Third Edition The Trivia Game Application Lesson C Objectives Connect a SQL Server database to an application Bind field objects to controls in an interface Position the record pointer in a dataset Determine the number of records in a dataset

44 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application Review requirements for Trivia Game application –Display questions along with answers –Allow user to select from set of answers –Track number of incorrect answers –Display information at the end of the game Location of partial solution –VB2005\Chap12\Trivia Game Solution folder First set of tasks –Connect application to Trivia.mdf, define dataset

45 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application (continued) Figure 12-47: Completed Add Connection dialog box

46 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application (continued) Figure 12-49: TriviaDataSet added to the Data Sources window

47 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application (continued) Tasks following definition of the dataset –Preview data that can be displayed –Bind field objects to text boxes Three event procedures to code –xExitButton’s Click event procedure –MainForm’s Load event procedure –xSubmitButton’s Click event procedure Test the application after all code is added

48 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application (continued) Figure 12-51: Question field object being dragged to the xQuestionTextBox

49 Programming with Microsoft Visual Basic 2005, Third Edition Coding the Trivia Game Application (continued) Figure 12-55: Pseudocode for the xSubmitButton’s Click event procedure

50 Programming with Microsoft Visual Basic 2005, Third Edition Summary – Lesson C First step for accessing a database: connect the application to a database Following connection to database, specify field objects that will form a dataset Dataset objects can be bound to interface controls Methods of BindingSource objects enable you to move through records