Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Accessing Databases with ADO.NET, Handling Exceptions, and Printing"— Presentation transcript:

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

2 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

3 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

4 Creating the Compensation Review Report Application

5

6

7

8 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)

9 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

10 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:

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

12 Try…Catch Exception Handling

13 Try…Catch Exception Handling

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

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

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

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

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

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

20 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

21 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

22 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

23 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 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 and VB Add the MonthCalendar control to the GroupBox1 control. Add the two RadioButton controls to the GroupBox2 control

24

25 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:

26 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

27 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:

28 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

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

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

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

32 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

33 Sending Output to a Printer and Catching an Exception

34 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

35 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

36 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

37 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

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

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

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

41 Using a Report Expert to Create a Report

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

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

44 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

45 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

46 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

47 Using the CrystalReportViewer Control

48 Running a Crystal Reports Report

49 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

50 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

51 Chapter 10 Complete


Download ppt "Accessing Databases with ADO.NET, Handling Exceptions, and Printing"

Similar presentations


Ads by Google