ADO.NET Application: Bethesda Car Rental



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 or no code. To illustrate this, we will create an application that would help a company that rents cars.


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 Application named bcr1
  21. To change the name of the form, in the Solution Explorer, right-click Form1.cs and click Rename
  22. Type Central.cs and press Enter
  23. To create a new form, on the main menu, click Project -> Add Windows Form...
  24. Set the name to Employees and click Add
  25. On the main menu, click Data -> Show Data Sources
  26. Click Add New Data Source...
  27. In the first page of the Data Source Configuration Wizard, make sure that Database is selected and click Next
  28. 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
  29. Change the name of the connection string to strBCRConnection and click Next
  30. Expand the Tables node and click the check box of Employees
  31. Change the DataSet Name to dsBCR
  32. Click Finish
  33. 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
  34. 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
  35. Click OK
  36. Set DataGridView's Anchor property to Top, Bottom, Left, Right
  37. Under the DataGridView control, add a button and set its properties as follows:
    Text: Close
    (Name): btnClose
    Anchor: Bottom, Right
  38. Double-click the Close button and implement its even as follows:
    private void btnClose_Click(object sender, EventArgs e)
  39. Access the Central form
  40. Add a button to it and set its properties as follows:
    Text: Employees
    (Name): btnEmployees
  41. Double-click the Employees button and implement its even as follows:
    private void btnEmployees_Click(object sender, EventArgs e)
        Employees frmEmployees = new Employees();
  42. Execute the application to test it
  43. Access the Employees form
  44. 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
  45. Close the forms

Home Copyright © 2006-2008, FunctionX, Inc. Next