Home

ADO.NET Application: Bethesda Car Rental

 

Introduction

It used to be an arduous process to create a database using Microsoft ActiveX Data Objects  (ADO). You had to know a great deal of the ADOX and ADO libraries. When Microsoft developed the .NET Framework and the new process of creating a database through the ADO.NET technique, database development was significantly simplified but you were still required to write some code to perform some of the routine operations.

As implemented in Microsoft Visual Studio 2005, ADO.NET has become even easier, so easy that you can create a complete functional graphical database with little to no code. To illustrate this, we will create an application that would help a company that rents cars to perform daily business operations.

Employees

We will start our database with the list of employees of the company, who are people who process daily rental transactions.

Practical Learning Practical Learning: Introducing the Application

  1. To start the database, click Start -> All Programs -> Microsoft SQL Server 2005 -> SQL Server Management Studio
  2. Select or accept the Server Type, the Server Name, and the Authentication
  3. Click Connect
  4. Expand the Databases node
  5. To create a new database, right-click the Databases node and click New Database...
  6. Set the database name to bcr (which stands for Bethesda Car Rental) and accept the default owner or change it
  7. Click OK
  8. Expand the bcr node and the Tables node under it
  9. To create a new table, right the Tables node under bcr and click New Table...
  10. Set the first column name to EmployeeID
  11. Set its Data Type to int
  12. In the lower section, expand Identity Specification and set the (Is Identify) field to Yes
  13. On the Table Designer toolbar, click the Set Primary Key button
  14. Complete the table with the following columns
     
    Column Name Data Type Allow Nulls
    EmployeeID int  
    FirstName varchar(30)  
    LastName varchar(30) Uncheck
    Title varchar(50)  
    HourlySalary decimal(8,2)  
  15. Save the table as Employees and close it
  16. In the Object Explorer, right-click dbo.Employees and click Open Table
  17. Create the following records:
     
    EmployeeID FirstName LastName Title HourlySalary
    1 Patricia Katts Regional Manager 28.45
    2 Julienne Mukoko Sales Manager 26.65
    3 Bertrand Yamaguchi Sales Representative 12.85
    4 Hermine Calhoun Sales Representative 11.95
  18. Close the table
  19. Microsoft Visual C++ 2005 or Microsoft Visual Studio
  20. Create a Windows Forms Application named bcr1
     
  21. To create a new form, on the main menu, click Project -> Add New Item...
  22. In the Templates list, click Windows Form and set the name to Employees
     
  23. Click Add
  24. On the main menu, click Data -> Show Data Sources
  25. Click Add New Data Source...
  26. In the first page of the Data Source Configuration Wizard, make sure that Database is selected and click Next
  27. If a bcr connection appears in the combo box, fine; if not, click New Connection and create a connection to the bcr database. Click Next
  28. Expand the Tables node and click the check box of Employees
  29. Change the DataSet Name to dsEmployees. Click Finish
  30. In the Data Sources window, click Employees and click the arrow of its combo box to select DataGridView (it should be selected already as the default).
    Drag the Employees node and drop it on the form
  31. While the DataGridView control is still selected on the form, in the Properties window, click the ellipsis of the Columns field and make the following changes:
     
    Selected Columns HeaderText Width
    EmployeeID Employee ID 75
    FirstName First Name 80
    LastName Last Name 80
    Title   130
    HourlySalary Hourly Salary 75
  32. Click OK
  33. Set DataGridView's Anchor property to Top, Bottom, Left, Right
  34. Under the DataGridView control, add a button and set its properties as follows:
    Text: Close
    (Name): btnClose
    Anchor: Bottom, Right
     
  35. Double-click the Close button and implement its even as follows:
     
    System::Void btnClose_Click(System::Object^  sender,
    			    System::EventArgs^  e)
    {
    	 Close();
    }
  36. Access the first form
  37. Add a button to it and set its properties as follows:
    Text: Employees
    (Name): btnEmployees
  38. Double-click the Employees button
  39. In the top section of the file, under the #pragma once line, type #include "Employees.h"
  40. Scroll to the bottom of the file and implement the even as follows:
     
    System::Void btnEmployees_Click(System::Object^  sender,
    				System::EventArgs^  e)
    {
    	 Employees ^ frmEmployees = gcnew Employees;
    	 frmEmployees->ShowDialog();
    }
  41. Execute the application to test it
  42. Access the Employees form
  43. Using the + button, add the following employees:
     
    EmployeeID FirstName LastName Title HourlySalary
    5 Olivier Perez Personnel Manager 24.05
    6 Henry James Sales Representative 12.05
    7 Emile Bemba Sales Representative 14.15
     
  44. Close the forms
 

Home Copyright © 2006 FunctionX, Inc. Next