Home

Data Entry

 

Fundamentals of Table Data Entry

 

Introduction

Data entry consists of populating a table with the necessary values it is supposed to hold. In the previous lessons, we saw that, to organize its data, a table is divided in sections called columns. The values common to an entry under each column constitute a row or record and a row is made of cells: as you may realize, everything we reviewed about the organization of a table, when studying data sets, is also valid here.

Data entry consists of filling the cells under the columns of a table.

Practical Learning Practical Learning: Introducing Data Entry

  1. Start a new Windows Forms Application named Countries3
  2. Right click the form and click View Code
  3. In the top section of the file, under the other using namespace lines, type:
     
    using namespace System::Data::SqlClient;
  4. Design the form as follows:
     
    Control Name Text
    TabControl tabCountries  
    TabPage pgeMaintenance Maintenance
    Button btnCreateDB Create Statistics Database
    Button btnCreateContinents Create Continents
    Button btnCreateCountries Create Countries
    TabPage pgeContinents Continents
    TabPage pgeCountries Countries
    Button btnClose Close
  5. Double-click the Create Statistics Database button and implement its code as follows:
     
    private: System::Void btnCreateDB_Click(System::Object *  sender, System::EventArgs *  e)
    
    {
    
    	 String *strConnection = String::Concat(S"IF EXISTS (SELECT * "
    
                                                                                    S"FROM   master..sysdatabases "
    
    				                S"WHERE  name = N'CountriesStats')"
    
    				                S"DROP DATABASE CountriesStats;"
    
    					S"CREATE DATABASE CountriesStats;");
    
    	SqlConnection *conDatabase = new 
    
    		SqlConnection(S"Data Source=(local);Integrated Security=sspi");
    
    	 SqlCommand    *cmdDatabase = new SqlCommand(strConnection, conDatabase);
    
    
    
    	 conDatabase->Open();
    
    
    
    	 cmdDatabase->ExecuteNonQuery();
    
    	 conDatabase->Close();
    
    }
  6. Return to the form and double-click the Create Continents button
  7. Implement its Click event as follows:
     
    private: System::Void btnCreateContinents_Click(System::Object *  sender, System::EventArgs *  e)
    
    {
    
    	 String *strCreate = S"IF EXISTS(SELECT name FROM sysobjects "
    
    		                 S"WHERE  name = N'Continents' AND type = 'U')"
    
    			 S"DROP TABLE Continents;"
    
    			 S"CREATE TABLE Continents ("
    
    			 S"ContinentName varchar(100),"
    
    			 S"Area varchar(30), "
    
    			 S"Population varchar(30));";
    
    
    
     	SqlConnection *conDatabase = new SqlConnection(
    
    		S"Data Source=(local);Database='CountriesStats';Integrated Security=yes");
    
    	 SqlCommand    *cmdDatabase = new SqlCommand(strCreate, conDatabase);
    
    
    
    	 conDatabase->Open();
    
    
    
    	 cmdDatabase->ExecuteNonQuery();
    
    	 conDatabase->Close();
    
    }
  8. Return to the form and double-click the Create Countries button
  9. Implement its Click event as follows:
     
    private: System::Void btnCreateCountries_Click(System::Object *  sender, System::EventArgs *  e)
    
    {
    
    	 String *strCreate = S"IF EXISTS(SELECT name FROM sysobjects "
    
    		                 S"WHERE  name = N'Countries' AND type = 'U')"
    
    			 S"DROP TABLE Countries;"
    
    			 S"CREATE TABLE Countries ("
    
    			 S"CountryName varchar(120),"
    
    			 S"Area varchar(30),"
    
    			 S"Population varchar(30),"
    
    			 S"Capital varchar(80),"
    
    			 S"Code char(2));";
    
    
    
     	SqlConnection *conDatabase = new SqlConnection(
    
                                  S"Data Source=(local);Database='CountriesStats';Integrated Security=yes");
    
    	 SqlCommand    *cmdDatabase = new SqlCommand(strCreate, conDatabase);
    
    
    
    	 conDatabase->Open();
    
    
    
    	 cmdDatabase->ExecuteNonQuery();
    
    	 conDatabase->Close();
    
    }
  10. Return to the form and double-click the Close button
  11. Implement its event as follows:
     
    private: System::Void btnClose_Click(System::Object *  sender, System::EventArgs *  e)
    
    {
    
    	 Close();
    
    }
  12. Execute the application
  13. Click the top button and wait a few seconds
  14. Click the middle button and wait a few seconds
  15. Click the bottom button and wait a few seconds
  16. Close the form and return to your programming environment

Displaying the Table For Data Entry

Before performing data entry from the SQL Server Enterprise Manager, you must first open it in a view that display its records. To do this, you can locate the database it belongs to and click the Tables node. In the right frame, click the table's name to select it. Then, on the main menu, click Action -> Open Table -> Return all rows. Alternatively, you can right-click the table in the right frame, position the mouse on Open Table, and click Return all rows.

If you are working in Server Explorer, expand the name of the server under the Servers node, then expand SQL Servers, followed by the name of the server, followed by the database, and followed by the Tables node. Finally, double-click the desired table.

If this is the first time you open the table for data entry, it would display the label of each column on top and empty cells under it:

If the table already contains some records, they would display under the column headers.

 
 

Previous Copyright 2005 FunctionX, Inc. Next