Introduction to Data Entry



This is an introduction to creating records for a database table.

Practical LearningPractical Learning: Introducing Data Selection

  1. Start Microsoft SQL Server and connect
  2. Right-click the server name and click New Query
  3. To create a new database, in the empty window, type the following:
    USE master;
    CREATE DATABASE ApartmentsManagement1;
    USE ApartmentsManagement1;
    CREATE SCHEMA Listing;
    CREATE TABLE Listing.Apartments
        UnitNumber nvarchar(10),
        Bedrooms tinyint,
        Batrhrooms float,
        MonthlyRate money,
        SecurityDeposit money,
        Availability nvarchar(25)
  4. To execute the SQL statement, press F5
  5. Start Microsoft Visual Studio
  6. To start a new project, on the main menu, click File -> New -> Project...
  7. Make sure Windows Forms Application is selected.
    Set the name to DataEntry101

    New Project

  8. Click OK
  9. Design the form as follows:
    Apartments Management
    Control Text Name DropDownStyle Items
    Label Unit Number:      
    Text Box   txtUnit Number    
    Label Bedrooms:      
    TextBox   txtBedrooms    
    Label Bathrooms:      
    TextBox   txtBathrooms    
    Label Monthly Rate:      
    TextBox   txtMonthlyRate    
    Label Security Deposit:      
    TextBox   txtSecurityDeposit    
    Label Availability:      
    ComboBox   cbxAvailability DropDownList Available
    Not Ready
    Needs Repair
    Button Close btnClose    
    Button Submit btnSubmit    
    Form Property Value
    FormBorderStyle FixedDialog
    Text Apartments Management
    StartPosition CenterScreen
    MaximizeBox False
    MinimizeBox False
  10. Double-click the Submit button
  11. Return to the form and double-click the Close button
  12. 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;
    using System.Data.SqlClient;
    namespace DataEntry101
        public partial class DataEntry : Form
            public DataEntry()
            private void btnSubmit_Click(object sender, EventArgs e)
                using (SqlConnection cApartments =
                	    new SqlConnection("Data Source=(local);" +
                    	              "Database='ApartmentsManagement1';" +
                            	      "Integrated Security=yes;"))
                    SqlCommand cmdApartments =
                            new SqlCommand("INSERT INTO Listing.Apartments " +
                                           "VALUES(N'" + txtUnitNumber.Text + "', " + 
                                           int.Parse(txtBedrooms.Text) + ", " + 
                                           float.Parse(txtBathrooms.Text) + ", " + 
                                           double.Parse(txtMonthlyRate.Text) + ", " + 
                                           double.Parse(txtSecurityDeposit.Text) + ", N'" + 
                                           cbxAvailability.Text + "');",
                    MessageBox.Show("A new record has been created.",
                                    "Apartments Management",
            private void btnClose_Click(object sender, EventArgs e)
  13. Execute the application
  14. Enter the values as follows:
    Unit Number:      6200-8048
    Bedrooms:           2
    Bathrooms:          1
    Monthly Rate:      1150
    Security Deposit: 500
    Availability:         Occupied
  15. Click the Submit button
    Apartments Management
  16. Change the file as follows:
  17. Execute the application
  18. Enter the following values:
    Letter Grade: A
    Minimum Range: 4.00
    Minimum Percentage: 95
    Maximum Percentage: 100
    Descriptor: Excellent
  19. Click the Close button

Previous Copyright © 2013 FunctionX Next