Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.

Slides:



Advertisements
Similar presentations
1 After completing this lesson, you will be able to: Create a database. Create a table using the Table Wizard. Create and modify a table in Design view.
Advertisements

Benchmark Series Microsoft Access 2010 Level 1
Microsoft Office 2007 Access Chapter 3 Maintaining a Database.
Using Macros and Visual Basic for Applications (VBA) with Excel
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
Microsoft Excel 2010 Chapter 7
Chapter 1 Databases and Database Objects: An Introduction
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Access Tutorial 1 Creating a Database
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 3 Maintaining a Database Using the Design and Update Features of Access.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 4 Reports, Forms, and Combo Boxes.
Chapter 2 Querying a Database
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
Microsoft Visual Basic 2012 CHAPTER TWELVE (ENRICHMENT CHAPTER) Windows Store Apps.
Chapter 3 Maintaining a Database
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Chapter 2 Querying a Database MICROSOFT ACCESS 2010.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 1 Databases and Database Objects: An Introduction
Chapter 6 Advanced Report Techniques
IE 411/511: Visual Programming for Industrial Applications
Microsoft Expression Web-Illustrated Unit I: Working with Tables.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 5 Enhancing Forms with OLE Fields, Hyperlinks, and Subforms.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 5 Enhancing Forms with OLE Fields, Hyperlinks, and Subforms.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
XP Practical OpenOffice.org Chapter 8 1 Creating a Presentation.
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 Office 2013 Access Creating a Database.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
1 Database Design and Development: A Visual Approach © 2006 Prentice Hall Chapter 12 DATABASE DESIGN AND DEVELOPMENT: A VISUAL APPROACH Chapter 12 Accessing.
1 Chapter 10 – Database Management 10.1 An Introduction to Databases 10.2 Editing and Designing Databases.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 6 BACKNEXTEND 6-1 LINKS TO OBJECTIVES Using the Report Button Using the Report Button Print.
1 After completing this lesson, you will be able to: Create a form using AutoForm. Create a form using the Form Wizard. Add controls to a form. Modify.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Prepared by the Academic Faculty Members of IT. Tables Creating Tables. Merging Cells. Splitting Cells. Sorting Tables. Performing Calculations.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPREHENSIVE Access Tutorial 1 Creating a Database.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
Excel Chapter 1 Creating a Worksheet and an Embedded Chart
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Integrating Office 2003 Applications and the World Wide Web
Maintaining a Database
Incorporating Databases with ADO.NET
Enhancing Forms with OLE Fields, Hyperlinks, and Subforms
Incorporating Databases with ADO.NET
Microsoft Office Access 2003
Microsoft Office Access 2003
Presentation transcript:

Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET

10 Objectives ►Understand database files ►Connect to a database using ADO.NET 4.5 ►Use multiple database types ►Connect Form objects to the data source ►Bind database fields to the Windows Form object ►Access database information on a Windows Form object Chapter 10: Incorporating Databases with ADO.NET2

10 Objectives ►Add a record ►Delete a record ►Select records from a list ►Program beyond the Database Wizard ►Create the OleDbDataAdapter object Chapter 10: Incorporating Databases with ADO.NET3

10 Chapter Project Chapter 10: Incorporating Databases with ADO.NET4

10 Database Files ►A database is a collection of related information stored in a structured format ►A database organizes data in tables ►Each row is referred to as a record ►Each column in a table is referred to as a field ►A unique field is an identifier that represents the primary key for the table Chapter 10: Incorporating Databases with ADO.NET5

10 Establishing a Database Connection ►Create a Windows application named Urban Gardens. Name the form frmGarden. Change the Text property to Urban Gardening. Resize the form to a size of 780, 530. Change the BackColor property to White on the Web tab. An image representing one of the local gardeners named Garden.jpg is available with your Data Files. Place a PictureBox object on the left side of the window. Name the PictureBox object picGarden. Change the Size property to 255,160. Make the location 24,30. Using the Image property, import the Garden.jpg image for the PictureBox object Chapter 10: Incorporating Databases with ADO.NET6

10 Establishing a Database Connection ►Change the SizeMode to StretchImage. On the right side of the form, place a Label object named lblTitle. Change the Text property to Urban Gardens. Make the Font property Script MT, Bold, size 40, and the ForeColor property Green on the Web tab. Change the Location property of the lblTitle Label object to 300,65. Close the Toolbox, and then tap or click PROJECT on the menu bar ►Tap or click ‘Add New Data Source’ on the PROJECT menu ►In the Choose a Data Source Type dialog box, tap or click Database, and then tap or click Next. In the Choose a Database Model dialog box, tap or click Dataset, and then tap or click Next Chapter 10: Incorporating Databases with ADO.NET7

10 Establishing a Database Connection ►Tap or click the New Connection button. In the Add Connection dialog box, tap or click the Change... button to select the data source ►In the Choose Data Source dialog box, select Microsoft Access Database File because the Garden database is an Access database. Tap or click the OK button ►Tap or click the Browse button to the right of Database file name. Select the USB device on the E: drive, and then select the file named Garden Chapter 10: Incorporating Databases with ADO.NET8

10 Establishing a Database Connection ►Tap or click the Open button ►Tap or click the OK button in the Add Connection dialog box ►Click the Next button ►Click the No button and then tap or click the Next button. When the Choose Your Database Objects dialog box opens, select which database objects you want in the DataSet. Tap or click the expand icon next to the Tables option. Tap or click the Gardener check box to select that table. A connection is made from the Visual Basic application to the Gardener table within the Garden.accdb database ►Tap or click the Finish button. Tap or click GardenDataSet.xsd to select the DataSet Chapter 10: Incorporating Databases with ADO.NET9

10 Establishing a Database Connection Chapter 10: Incorporating Databases with ADO.NET10

Connecting Form Objects to the Data Source ►In the Garden project window, point to the Data Sources tab on the left side of the window. If the Data Sources tab is not visible, tap or click VIEW on the menu bar, tap or click Other Windows and then tap or click Data Sources ►Tap or click Data Sources to view the database sources ►Tap or click the expand icon for the Gardener table to expand the list of field names within the table. Each bindable field item in the Data Sources window can be placed on the Windows Form object Chapter 10: Incorporating Databases with ADO.NET11

10 Connecting Form Objects to the Data Source Chapter 10: Incorporating Databases with ADO.NET12

10 Binding Database Fields to the Windows Form ►Select the Plot ID field in the Data Sources window. Drag the Plot ID field to the Windows Form object, below the PictureBox object ►Drag the rest of the field objects from the Data Sources window to the Windows form. Select all the field labels and field TextBox objects and change the font to size 10 points. Use the formatting tools on the FORMAT menu to equally distribute the bound objects. You can select the Label and the TextBox objects separately to move them independently of each other. Use the layout shown in Figure on page 712 ►Run the application by tapping or clicking the StartDebugging button on the Standard toolbar to fill the Windows Form object with the data from the Gardener table. Use the Move next button on the navigation toolbar to move through the records. Tap or click the Move last button to display the last record Chapter 10: Incorporating Databases with ADO.NET13

10 Binding Database Fields to the Windows Form Chapter 10: Incorporating Databases with ADO.NET14

10 Adding a Record ►Tap or click the Start Debugging button on the Standard toolbar to run the Urban Garden application ►Tap or click the Add new button to add a new record to the database table ►Add a new record by typing the Plot ID, 777.Type the rest of the information as displayed in Figure on page 716. After the record is complete, tap or click the Save Data button on the BindingNavigator control to save the new record to the original database Chapter 10: Incorporating Databases with ADO.NET15

10 Adding a Record Chapter 10: Incorporating Databases with ADO.NET16

10 Deleting Records ►Tap or click the Start Debugging button on the Standard toolbar to execute the Intuition Urban Gardens application ►Use the navigation buttons to move to Tracy Tirrell’s record. Her garden record should be deleted because she is moving from the area. Tap or click the Delete button on the BindingNavigator control to delete her record from the database table. Tap or click the Save Data button to remove the record from the original database Chapter 10: Incorporating Databases with ADO.NET17

10 Deleting Records Chapter 10: Incorporating Databases with ADO.NET18

10 Selecting Records from a List ►Select the GardenerName Label object and TextBox object on the Windows form. Press the DELETE key to delete the Gardener Name objects from the Windows form. Select the Gardener Name table field in the Data Sources window and then tap or click its list arrow ►Tap or click the ComboBox object from the Toolbox object listing for the Gardener Name field. Drag the Gardener Name field ComboBox object to the original location of the Name TextBox object on the Windows Form object. Change the font size to 10 and then align the ComboBox with the other objects on the Windows Form ►To fill the ComboBox object with the names of gardeners, the ComboBox object must be bound to the Gardener Name field. To bind the items to the ComboBox object, select the Gardener Name object on the Windows form and tap or click the Action tag on the Gardener Name ComboBox object Chapter 10: Incorporating Databases with ADO.NET19

10 Selecting Records from a List ►Tap or click the Use Data Bound Items check box on the ComboBox Tasks menu. The Data Binding Mode list is displayed. Tap or click the Data Source list arrow under the Data Binding Mode and then select the GardenerBindingSource to connect the table to the ComboBox object. Next, tap or click the Display Member list arrow and then select Gardener Name. Tap or click the Value Member list arrow and then tap or click Gardener Name in the list. Do not change the Selected value entry ►Tap or click the Start Debugging button on the Standard toolbar to run the application. After the Windows form opens, tap or click the list arrow on the Gardener Name ComboBox object ►Tap or click Ramona Coveny to move directly to the record containing the information for Ramona Coveny’s urban garden Chapter 10: Incorporating Databases with ADO.NET20

10 Selecting Records from a List Chapter 10: Incorporating Databases with ADO.NET21

10 Programming Beyond the Database Wizard Chapter 10: Incorporating Databases with ADO.NET22

10 Programming Beyond the Database Wizard ►Download the original Access database file Garden.accdb again to overwrite any data you added or deleted from the database. Open the Urban Gardens Windows application. Add a Button object named btnCost to the Windows Form object and change the Text property to Total Planting Cost. Change the font size to 12 and the ForeColor property to Green. Set the Size property for the button to 238, 35 and center the Button object horizontally across the form. Add a Label object named lblTotalPlantingCost with the Text property of 23 “X’s” and center the text. Change the font size to 12 points. Set the Visible property for the lblTotalPlanningCost Label object to False because the X’s should not be displayed when the program begins Chapter 10: Incorporating Databases with ADO.NET23

10 Programming Beyond the Database Wizard ►Double-tap or double-click the Total Planting Cost button to create the btnCost_Click event handler. To initialize the OleDbDataAdapter, enter the code in Figure on page 728 inside the click event. The first variable strSql is assigned the SQL statement that queries all the fields in the Gardener table. The second variable strPath is assigned the database driver for Access and the path to the Garden.accdb file. The third variable odaGarden is an instance of the OleDbDataAdapter ►After the first three variables are initialized, initialize the rest of the variables needed for the Button object event handler. An instance named datCost is initialized to represent the DataTable object. The intCount variable is used to count through a For loop. The last variable, decTotalCost, will contain the total amount of the spring planting costs Chapter 10: Incorporating Databases with ADO.NET24

10 Programming Beyond the Database Wizard ►Continuing inside the btnCost_Click event handler, enter the code in Figure on page 729 to fill the DataTable with the contents of the Gardener table. In the next line of code, the Dispose method to close the connection ►Enter the code in Figure on page 729 to create a For loop to increment through each record in the Gardener table. Because the rows are numbered 0 to 15, the upper range is one less than the numbers of rows in the table, making 16 records. The value in each Cost field is added to the value in the decTotalCost variable ►Enter the code in Figure on page 729 to display the total spring planting cost Chapter 10: Incorporating Databases with ADO.NET25

10 Program Design Chapter 10: Incorporating Databases with ADO.NET26

10 Program Design Chapter 10: Incorporating Databases with ADO.NET27

10 Event Planning Document Chapter 10: Incorporating Databases with ADO.NET28

10 Summary ►Understand database files ►Connect to a database using ADO.NET 4.5 ►Use multiple database types ►Connect Form objects to the data source ►Bind database fields to the Windows Form object ►Access database information on a Windows Form object Chapter 10: Incorporating Databases with ADO.NET29

10 Summary ►Add a record ►Delete a record ►Select records from a list ►Program beyond the Database Wizard ►Create the OleDbDataAdapter object Chapter 10: Incorporating Databases with ADO.NET30

Microsoft Visual Basic 2012 CHAPTER TEN COMPLETE Incorporating Databases with ADO.NET