Home

Introduction to Database Visual Support

A Data Source

Introduction

Practical LearningPractical Learning: Introducing Visual Database Support

  1. Start Microsoft Visual Studio
  2. To create a new application, on the main menu, click FILE -> New -> Project...
  3. Make sure Windows Forms Application. Set the Name to AltairRealtors2 and click OK
  4. To create a new database, in the Server Explorer, right-click Data Connections and click Create New SQL Server Database...
  5. In the Server Name combo box, select your server or type (local)
  6. Set the database name as AltairRealtors2 and click OK
  7. In the Server Explorer, right-click the AltairRealtors2 connection and click New Query
  8. Open the AltairRealtors2 file and select everything in the document
  9. Copy and paste it in the Query window
  10. Right-click inside the document and click Execute
  11. In the Solution Explorer, right-click Form1.cs and click Rename
  12. Type AltairRealtors.cs and press Enter twice

Adding a Data Source

Practical LearningPractical Learning: Creating a Binding Source

  1. If necessary, display the form.
    In the Toolbox, click Data and click BindingSource
  2. Click the form
  3. In the Properties window, change its (Name) to bsProperties
  4. Click DataSource and click the arrow of its combo box
  5. Click the + button of the Other Data Sources node to expand it
  6. Click the + button of the Project Data Sources node
  7. Click dsAltairRealtors

The Table Adapter

Introduction

After creating a data set and a data source, the next step is to indicate to each control where its data would come from.

The Binding Navigator

Introduction

If you drag a table from the Data Source window and drop it on a form, Microsoft Visual Studio adds the necessary Windows controls to the form and binds them to the columns of the table. To move from one record to another, you would need a way to navigate among the records. You can manually take care of this if you want. Alternatively, the .NET Framework provides a class named BindingNavigator that contains all the necessary functionality for this task.

There are various ways you can create a binding navigator:

Practical LearningPractical Learning: Generating Visual Objects

  1. Open the LambdaSquareApartments1 file and select everything in it the document
  2. Copy to the clipboard
  3. Display the Query window (if it not available, right-click any connection in the Server Explorer and click New Query)
  4. To create a new database, paste in the Query window
  5. Right-click inside the Query window and click Execute
  6. To create a new application, on the main menu, click FILE -> New -> Project...
  7. Make sure Windows Forms Application. Set the Name to LambdaSquareApartments1
  8. Click OK.
    If you are asked whether you want to save SQLQuery1.sql, click No
  9. On the main menu, click PROJECT -> Add New Data Source...
  10. On the first page of the wizard, make sure Database is selected and click Next
  11. On the second page of the wizard, make sure Dataset is selected and click Next
  12. In the third page of the wizard, click New Connection...
    If the Choose Data Source dialog box comes up, click Microsoft SQL Server and click Continue
  13. In the Server Name combo box, select the server or type (local)
  14. In the Select or Enter a Database Name combo box, select LambdaSquareApartments1
  15. Click OK
  16. On the Data Source Configuration Wizard, make sure the new connection is selected
    Click the + button of Connection String
  17. Click Next
  18. Change the connection string to csLambdaSquareApartments and click Next
  19. Click the check boxes of Tables and Stored Procedures
  20. Change the name of the data set to dsLambdaSquareApartments
  21. Click Finish
  22. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  23. Set the Name to Apartments and click Add
  24. From the Data Source, drag Apartments and drop it on the new form
  25. Design the form as follows:
     
    Lambda Square Apartments - Listing
  26. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  27. Set the Name to Employees and click Add
  28. From the Data Source, drag Employees and drop it on the new form
  29. Design the form as follows:
     
    Lambda Square Apartments - Employees
  30. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  31. Set the Name to Registrations and click Add
  32. From the Data Source, drag Registrations and drop it on the new form
  33. Design the form as follows:
     
    Lambda Square Apartments - Registrations
  34. To create a new form, on the main menu, click PROJECT -> Add Windows Form...
  35. Set the Name to Payments and click Add
  36. From the DataSource, drag Payments and drop it on the form
  37. Design the form as follows:
     
    Lambda Square Apartments - Payments
  38. In the Solution Explorer, right-click Form1.cs and click Rename
  39. Type LambdaSquareApartments.cs and press Enter twice
  40. Design the form as follows:
     
    Lambda Square Apartments
    Control (Name) Name
    Button Button btnRegistrations Tenants Registrations...
    Button Button btnRentPayments Rent Payments...
    Button Button btnApartments Apartments...
    Button Button btnEmployees Employees...
    Button Button Close btnClose
  41. Double-click the Tenants Registrations button
  42. Return to the form and double-click the Rent Payments button
  43. Return to the form and double-click the Apartments button
  44. Return to the form and double-click the Employees button
  45. Return to the form and double-click the Close button
  46. Implement the events as follows:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace LambdaSquareApartments1
    {
        public partial class LambdaSquareApartments : Form
        {
            public LambdaSquareApartments()
            {
                InitializeComponent();
            }
    
            private void btnRegistrations_Click(object sender, EventArgs e)
            {
                Registrations regs = new Registrations();
                regs.Show();
            }
    
            private void btnRentPayments_Click(object sender, EventArgs e)
            {
                Payments pmts = new Payments();
                pmts.Show();
            }
    
            private void btnApartments_Click(object sender, EventArgs e)
            {
                Apartments aparts = new Apartments();
                aparts.Show();
            }
    
            private void btnEmployees_Click(object sender, EventArgs e)
            {
                Employees empls = new Employees();
                empls.Show();
            }
    
            private void btnClose_Click(object sender, EventArgs e)
            {
                Close();
            }
        }
    }
   
  1. Execute the application
  2. Click the Employees button, click the Add New button, add the values, and click the Save button. The records to create are:
     
    Employee # First Name Last Name Title
    40685 Justine Sandt Rent Manager
    73048 Raymond Wilkinson  
    60949 Mark Reason Maintenance Technician
    38408 Marc Knights Rent Associate
    93947 Leonard Goulet Owner - General Manager
    20448 Nancy Longhorn Rent Associate
  3. Click the Tenants Registrations button, click the Add New button, add the values, and click the Save button. The records to create are:
     
    Regist Date Employeee # Tenant Code First Name Last Name Marital Status Tenancy Children Phone # Email Address Unit Start Date
    2014-06-12 38408   29-485-05 Ann Sanders Married Active 1 (240) 524 -2831 annsanders@emailcity.com 139749 2014-07-01
    2014-06-15 20448   83-400-85 Mahty Shaoul Married Active 2 202-729-1574 mshaoulman@gmail.com 928364 2014-09-01
    2014-06-22 40685   48-602-73 Frank Ulm Single Active 0 (301) 882-0704 fulm112244@yaho.com 729397 2014-07-01
    2014-06-22 93947   24-385-30 Elizabeth Provoski Separated Active 1 (443) 974-9631 eprevalence@yahoo.com 844850 2014-08-01
    2014-07-23 93947   92-048-11 Grace Curryan Married Active 1 (240) 927-0993 gcarrier@gmail.com 297297 2014-09-01
    2014-07-25 38408   51-304-58 Tracy Warrens Divorced Active 2 202-793-6924 twarrior12@hotmail.coom 492739 2014-08-01
    2014-08-01 38408   72-384-04 Paul Yamo Married Active 3 (410-792-7045 pyamo@hr.umd.edu 384068 2014-10-01
    2014-08-10 40685   62-405-29 Nancy Shermann Single Active 1 (703) 338-2973 nsherre@emailcity.com 829475 2014-09-01
    2014-09-12 20448   72-484-04 Michael Tiernan Single Active 0 301-274-9285 resdev.globelan.net 829479 2014-11-01
    2014-10-05 38408   60-285-83 Phillippe Anderson Single Active 0 202-729-1574 philanders@gmail.com 496055 2014-11-01
  4. Click the Rent Payments button, click the Add New button, add the values, and click the Save button. The records to create are:
     
    Pmt Date Employee # Regist Date Amt Paid Notes
    2014-06-12 38408   1001 650.0000 This is the payment for the security deposit.
    2014-06-20 40685   1003 500.0000 Security Deposit
    2014-07-27 38408   1003 925.0000  
    2014-07-28 38408   1001 1150.0000  
    2014-08-01 40685   1006 850.0000 Security Deposit
    2014-08-08 40685   1007 850.0000 Security Deposit
    2014-08-08 40685   1008 500.0000 Security Deposit
    2014-08-13 40685   1004 600.0000 Security Deposit
    2014-08-14 20448   1002 850.0000 Payment for security deposit
    2014-08-25 38408   1001 1150.0000  
    2014-08-25 38408   1002 1350.0000  
    2014-08-26 20448   1003 925.0000  
    2014-08-27 40685   1004 1100.0000  
    2014-08-30 38408   1006 1350.0000  
    2014-09-17 40685   1009 650.0000 Security Deposit
    2014-09-18 20448   1005 550.0000 Security Deposit
    2014-09-25 20448   1004 1100.0000  
    2014-09-25 20448   1006 1350.0000  
    2014-09-25 20448   1008 885.0000  
    2014-09-28 20448   1001 1150.0000  
    2014-09-28 40685   1002 1350.0000  
    2014-09-28 40685   1005 1150.0000  
    2014-10-05 38408   1003 925.0000  
    2014-10-08 40685   1010 500.0000 Security Deposit
    2014-10-24 38408   1004 1100.0000  
    2014-10-24 38408   1005 1150.0000  
    2014-10-25 40685   1006 1350.0000  
    2014-10-25 40685   1007 1250.0000  
    2014-10-27 93947   1001 1150.0000  
    2014-10-29 93947   1008 885.0000  
    2014-10-30 38408   1002 1350.0000  
    2014-10-31 40685   1003 925.0000  
    2014-11-26 38408   1002 1350.0000  
    2014-11-26 38408   1008 885.0000  
    2014-11-27 38408   1006 1350.0000  
    2014-11-28 20448   1004 1100.0000  
    2014-11-28 38408   1005 1150.0000  
    2014-11-28 38408   1007 1250.0000  
    2014-11-29 93947   1001 1150.0000  
    2014-11-30 38408   1003 925.0000  
    2014-11-30 20448   1009 1150.0000  
    2014-11-30 20448   1010 895.0000  
    2014-12-25 38408   1006 1350.0000  
    2014-12-25 38408   1007 1250.0000  
    2014-12-27 20448   1009 1150.0000  
    2014-12-28 20448   1001 1150.0000  
    2014-12-28 38408   1004 1100.0000  
    2014-12-28 38408   1005 1150.0000  
    2014-12-28 38408   1010 895.0000  
    2014-12-30 20448   1003 925.0000  
    2014-12-31 38408   1002 1350.0000  
    2014-12-31 20448   1008 885.0000  
    2015-01-23 20448   1005 1150.0000  
    2015-01-26 38408   1001 1150.0000  
    2015-01-28 93947   1003 925.0000  
    2015-01-29 93947   1002 1350.0000  
    2015-02-10 20448   1004 100.0000 This is a fee for late payment.
    2015-02-10 20448   1004 1100.0000  
    2015-02-20 20448   1001 1150.0000  
    2015-02-25 20448   1005 1150.0000  
    2015-02-26 38408   1002 1350.0000  
    2015-03-01 38408   1004 1100.0000  
    2015-03-03 40685   1003 925.0000  
  5. Close the forms and return to your programming environment