|
Introduction to Data Entry |
|
|
This is an introduction to creating records for a
database table.
|
Practical
Learning: Introducing Data Selection
|
|
- Start Microsoft SQL Server and connect
- Right-click the server name and click New Query
- To create a new database, in the empty window, type the following:
USE master;
GO
CREATE DATABASE ApartmentsManagement1;
GO
USE ApartmentsManagement1;
GO
CREATE SCHEMA Listing;
GO
CREATE TABLE Listing.Apartments
(
UnitNumber nvarchar(10),
Bedrooms tinyint,
Batrhrooms float,
MonthlyRate money,
SecurityDeposit money,
Availability nvarchar(25)
);
GO
- To execute the SQL statement, press F5
- Start Microsoft Visual Studio
- To start a new project, on the main menu, click File -> New ->
Project...
- Make sure Windows Forms Application is selected.
Set the name
to DataEntry101
- Click OK
- Design the form as follows:
|
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 Occupied Not Ready Needs Repair
Other |
Button |
Close |
btnClose |
|
|
Button |
Submit |
btnSubmit |
|
|
|
Form Property |
Value |
FormBorderStyle |
FixedDialog |
Text |
Apartments Management |
StartPosition |
CenterScreen |
MaximizeBox |
False |
MinimizeBox |
False |
- Double-click the Submit button
- Return to the form and double-click the Close button
- 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()
{
InitializeComponent();
}
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 + "');",
cApartments);
cApartments.Open();
cmdApartments.ExecuteNonQuery();
MessageBox.Show("A new record has been created.",
"Apartments Management",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
- Execute the application
- Enter the values as follows:
Unit Number: 6200-8048
Bedrooms: 2 Bathrooms: 1 Monthly Rate:
1150 Security Deposit: 500 Availability: Occupied
- Click the Submit button
- Change the file as follows:
- Execute the application
- Enter the following values:
Letter Grade: A Minimum Range:
4.00 Minimum Percentage: 95 Maximum Percentage: 100
Descriptor: Excellent
- Click the Close button
|
|