Home

A Set of Data

 

A Set of Data

 

Introduction

We have defined a database as a list of items. The nature of the items is not particularly important because any list of any type of items constitutes a database. The idea of considering it a database is for better organization of management. This means that, traditionally, the database word suggests that the list must be formally created, either on a piece of paper or on a computer file. Any type of thing can be made into a list. This means that one list can be made of people. Another list can be made of CDs. Another list can be made of countries. Because of this, before creating a list, you should first plan it by deciding what kinds of items would compose the list.

A item that is part of a list is called datum, with the plural being data, but data is also used for singular. The group of items, or data, that makes up a list is referred to as a set of data.

Data Set Creation

To support the creation and management of any type of list, the .NET Framework provides the DataSet class, which is defined in the System::Data namespace. Therefore, to create a list, you can start by declaring a variable of type DataSet. To initialize a DataSet variable, the class is equipped with three constructors, the first of which is the default, meaning it doesn't take any argument. The DataSet default constructor allows you to declare a variable without providing further information, just to let the compiler know that you are going to create or need a list of items. Here is an example:

System::Void btnCreate_Click(System::Object *  sender, System::EventArgs *  e)

{

	 DataSet *dsVideoCollection = new DataSet();

}

If you are planning to use a DataSet object from more than one method or event, you can declare it globally, that is, in the class of a form. Here is an example:

#pragma once





namespace Application1

{

	using namespace System;

	using namespace System::ComponentModel;

	using namespace System::Collections;

	using namespace System::Windows::Forms;

	using namespace System::Data;

	using namespace System::Drawing;



	. . . No Change

	

	public __gc class Form1 : public System::Windows::Forms::Form

	{	

	public:

		. . . No Change



	private:

		/// <summary>

		/// Required designer variable.

		/// </summary>

		System::ComponentModel::Container * components;

		DataSet *dsVideoCollection;



		/// <summary>

		/// Required method for Designer support - do not modify

		/// the contents of this method with the code editor.

		/// </summary>

		void InitializeComponent(void)

		{

			. . . No Change

		}	



	private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)

			 {

				 dsVideoCollection = new DataSet;

			 }

	};

}

When creating a set of data, it is not unusual that you want to give it a name. This would allow you to refer to the list later on by its formal name. To create such a set, you can use the second constructor whose syntax is:

puclic: DataSet(String *name);

This constructor takes as argument the formal name of the set. The name can be anything but it must respect the rules of names of the C++ language. Here is an example:

System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)

{

	 dsVideoCollection = new DataSet(S"Videos");

}

The third constructor is not used in your applications.

The name of the DataSet variable, in this case dsVideoCollection, is a Windows name that will allow the operating system to identify the DataSet. That name is required as is the case for every variable you declare. The DataSetName name is optional but is useful in many methods as we will see. If you don't specify it, the compiler would generate a default name for the DataSet object.

Instead of programmatically declaring a DataSet variable, the Visual Studio .NET programming environment allows you to do this "visually" by clicking the DataSet button from the Data section of the Toolbox and clicking a form or another container. If you create a DataSet using this approach, you can specify its name using the DataSetName property in the Properties window. In the same way, if you have already created the table using either the default or the second constructor and you want to set or change its name, assign a string to the DataSet::DataSetName property.

Practical Learning Practical Learning: Creating a DataSet

  1. Start Microsoft Visual Studio .NET and create a new Windows Forms Application named MusicStore1
  2. In the Toolbox, click the Data button.
    To create a DataSet, click DataSet and click the form
     
  3. In the Add Dataset dialog box, click the Untyped Dataset radio button and click OK
  4. While the DataSet control is still selected, in the Properties window, click (Name) and type dsMusicStore
  5. Still in the Properties window, set the DataSetName to MusicStore
 

Home Copyright © 2005-2016, FunctionX Next