Accessing Databases with ADO.NET, Handling Exceptions, and Printing

Slides:



Advertisements
Similar presentations
Using Advanced Cascading Style Sheets
Advertisements

Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 7 Creating an Online Form.
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
Microsoft Excel 2010 Chapter 7
Chapter 1 Databases and Database Objects: An Introduction
Integrating Access with the Web and with Other Programs.
Copyright 2007, Paradigm Publishing Inc. POWERPOINT 2007 CHAPTER 1 BACKNEXTEND 1-1 LINKS TO OBJECTIVES Create Presentation Open, Save, Run, Print, Close,Delete.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
Access Tutorial 10 Automating Tasks with Macros
Chapter 2 Querying a Database
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
Chapter 2 Querying a Database MICROSOFT ACCESS 2010.
Chapter 1 Databases and Database Objects: An Introduction
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
XP New Perspectives on Integrating Microsoft Office XP Tutorial 2 1 Integrating Microsoft Office XP Tutorial 2 – Integrating Word, Excel, and Access.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Learning With Computers II (Level Orange) ©2012 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Microsoft Access Lesson 2 Lexington Technology Center February 13, 2003 Bob Herring On the Web at
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
MS-Access XP Lesson 4. Modifying Queries 1.Select query in queries 2.Click design button or Right click on query and click design view 3.Change query.
1 After completing this lesson, you will be able to: Get around the Internet with your browser. Connect to the Internet. Print Web pages. Save Web pages.
Creating and Editing a Web Page
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.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
CS 281 – Fall 2010 Lab 4 Parametric Query and Forms in MS Access.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 12 Creating Console Applications, Understanding XML, and Creating Web Services.
Chapter 5 Using a Template to Create a Resume and Sharing a Finished Document Microsoft Word 2013.
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.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 5 BACKNEXTEND 5-1 LINKS TO OBJECTIVES Using the Form Button Using the Form Button Form Views.
Integrating Office 2003 Applications and the World Wide Web
Chapter 1 Managing Messages with Outlook
VB 2010 Pertemuan 10.
Practical Office 2007 Chapter 10
Access Chapter 2 Querying a Database.
Chapter 2 – Introduction to the Visual Studio .NET IDE
PowerPoint Web Feature
Incorporating Databases with ADO.NET
Access Creating Forms and Reports
Creating and Using a Database
Enhancing Forms with OLE Fields, Hyperlinks, and Subforms
Using Procedures and Exception Handling
Office 2010 and Windows 7: Essential Concepts and Skills
Incorporating Databases with ADO.NET
Chapter 7 Advanced Form Techniques
Using Frames in a Web Site
Integrating JavaScript and HTML
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
Microsoft Office Access 2003
Microsoft Office Access 2003
Chapter 1 Databases and Database Objects: An Introduction
Defining the Fields in a Table
Introduction to Internet Explorer
Shelly Cashman: Microsoft Word 2016
Shelly Cashman: Microsoft Windows 10
Tutorial 8 Sharing, Integrating, and Analyzing Data
Tutorial 10 Automating Tasks with Macros
Tutorial 4 Creating Forms and Reports
Presentation transcript:

Accessing Databases with ADO.NET, Handling Exceptions, and Printing Chapter 10 Accessing Databases with ADO.NET, Handling Exceptions, and Printing

Objectives Use the MonthCalendar control in an application Use the PrintDialog control in an application Use the PrintDocument control in an application Write code in a class Understand database connections Write code to connect to a database

Objectives Understand how the CLR handles exceptions during run time Code a Try…Catch…Finally statement to handle exceptions Read records from a database Understand the role of SQL in interacting with a database Use simple SQL SELECT statements to query a database Understand the functionality and major components of Crystal Reports

Creating the Compensation Review Report Application

Starting Visual Basic .NET and Adding a New Class to the Compensation Review Class Library Insert the Data Disk in drive A. Using Windows Explorer, copy the Compensation Review folder from the A:\Chapter9 folder to the A:\Chapter10 folder Start Visual Basic .NET. When the Start Page appears, click the Open Project button on the Start Page If necessary, click the Look in box arrow and then click 3½ Floppy (A:). Double-click the Chapter10 folder Double-click the Compensation Review folder. If necessary, click the Compensation Review solution file (Compensation Review.sln)

Starting Visual Basic .NET and Adding a New Class to the Compensation Review Class Library Click the Open button. When the Compensation Review project appears in the Solution Explorer window, right-click the Compensation Review project. When the shortcut menu appears, point to the Add command and then click Add Class on the Add menu Select the text in the Name box and type Employees.vb as then new name. Click the Open button

Declaring Private Variables and Creating a Database Connection String If necessary, double-click the Employees.vb class module in the Solution Explorer window. When the Employees.vb code window opens, type the code as shown below:

Declaring Private Variables and Creating a Database Connection String Type the code as shown below:

Try…Catch Exception Handling

Try…Catch Exception Handling

Preparing a Data Command and a Data Reader and Coding a Try…Catch Statement Enter lines 24 through 32, as shown below:

Connecting to a Database Type lines 12 through 24, as shown below:

Coding a SQL SELECT Statement to Read Hourly Employee Records Type lines 24 through 34, as shown below:

Completing Coding the SQL SELECT Statement Type lines 33 and 34, as shown below:

Using a Loop to Read Hourly Employee Records Type lines 35 through 48, as shown below:

Coding a SQL SELECT Statement and Looping to Read Salaried Employee Records Type lines 50 through 65, as shown below:

Building, Saving, and Documenting the Class Library Right-click the Compensation Review project in the Solution Explorer window. When the shortcut menu appears, click the Build command Use the Print command on the File menu to print a record of the code for the Employees class

Adding a New Project to a Solution Right-click the Compensation Review solution in the Solution Explorer. When the shortcut menu appears, point to the Add command Click the New Project command When the Add New Project dialog box appears, if necessary, click the Windows Application template in the Templates area. Select the text in the Name box, type Compensation Review Report as the new project name, and then click the OK button

Adding a New Project to a Solution Right-click the References folder for the Compensation Review Report and then click the Add Reference command on the References shortcut menu. When the Add Reference dialog box appears, click the Browse button and use the Select Component dialog box to add a reference to the Compensation Review.dll component located in the A:\Chapter10\Compensation Review\Compensation Review\bin folder

Setting Form Properties and Adding Controls With Form1 selected, set the properties of the Form1 form as specified in Table 10-4 on page VB 10.42. Add the controls to the form as shown below and set the property values of the controls as listed in Table 10-5 on pages VB 10.42 and VB 10.43. Add the MonthCalendar control to the GroupBox1 control. Add the two RadioButton controls to the GroupBox2 control

Changing the Properties of a MonthCalendar Control Click the MonthCalendar control. Change the Name property value for the MonthCalendar control to calReviewDate, as well as the remaining properties of the control as listed below:

Changing the Properties of PrintDialog and PrintDocument Controls Click the PrintDialog control in the Component Tray. Change the Name property value of the PrintDialog control as shown below Click the PrintDocument control in the Component Tray. Change the Name property value of the PrintDocument control as shown below

Using a PrintDialog Control and a PrintDocument Control in Code Double-click the btnPrint Button control on the Form1 form. When the code window appears, type the code as shown below:

Using a PrintDialog Control and a PrintDocument Control in Code Enter lines 135 through 139 as shown below. Visual Basic .NET automatically adds lines 134 and 140 to the code

Building a Report Header Type lines 142 through 170, as shown below:

Building the Report Body Enter lines 172 through 175 and 177 through 189, as shown below:

Finishing Building the Report Body Type lines 190 through 203, as shown below:

Sending Output to a Printer and Catching an Exception Click the Form1.vb[Design]* tab at the top of the code window. When the Form1 form appears, double-click the objPrintDocument control in the Component Tray Type lines 207 through 229, as shown on the following slide

Sending Output to a Printer and Catching an Exception

Setting the Startup Project, Saving the Project, and Testing the Project Click the Compensation Review solution in the Solution Explorer. Click the property value next to the Startup project property in the Properties window. Click the box arrow in the property value of the Startup project Click Compensation Review Report in the list box Click the Save All button on the Standard toolbar Click the Start button on the Visual Basic .NET Standard toolbar

Setting the Startup Project, Saving the Project, and Testing the Project When the Compensation Review Report application window appears, use the arrow buttons at the top of the MonthCalendar control to navigate the months and then select July 30, 2004 using the MonthCalendar control Click the Print Compensation Review Report button. When the Print dialog box appears, select a printer and then click the OK button Click the Close button on the Compensation Review Report application window title bar. If necessary, click the Visual Basic .NET taskbar button to display the Visual Basic .NET window. If necessary, close the Output window

Documenting the Application and Quitting Visual Basic .NET Click the Form1.vb[Design] tab and then use the PRINT SCREEN key to print a record of the user interface design of the Form1 form Click the Form1.vb tab. Click File on the menu bar and then click Page Setup When the Page Setup dialog box appears, if necessary, click Line numbers and then click the OK button Use the Print command on the File menu to print a record of the code for the Compensation Review Report application Click the Visual Basic .NET Close button

Adding a Crystal Report to a Project Add a Crystal Report module to a Windows application project by right-clicking the appropriate project in the Solution Explorer, pointing to Add on the shortcut menu, clicking Add New Item on the Add menu, and adding a report entitled CrystalReport1.rpt

Adding a Crystal Report to a Project Click the Open button on the Add New Item dialog box

Using a Report Expert to Create a Report Choose the Standard Report Expert and click OK

Using a Report Expert to Create a Report Select the OLE DB (ADO) data source, and choose the second item in the provider list

Using a Report Expert to Create a Report

Using a Report Expert to Create a Report On this screen, you are able to fill in any additional, necessary database parameters

Using a Report Expert to Create a Report Select the tables you wish to appear in the report, and click the Next button

Using a Report Expert to Create a Report If necessary, you can add additional links to the tables on the Links tab before clicking the Next button

Using a Report Expert to Create a Report The Fields tab allows you to specify which fields from the tables to print on the report

Using a Report Expert to Create a Report After clicking the Finish button on the Standard Report Expert dialog box, you are able to view and modify the report layout

Using the CrystalReportViewer Control

Running a Crystal Reports Report

Summary Use the MonthCalendar control in an application Use the PrintDialog control in an application Use the PrintDocument control in an application Write code in a class Understand database connections Write code to connect to a database

Summary Understand how the CLR handles exceptions during run time Code a Try…Catch…Finally statement to handle exceptions Read records from a database Understand the role of SQL in interacting with a database Use simple SQL SELECT statements to query a database Understand the functionality and major components of Crystal Reports

Chapter 10 Complete