A Data Set |
|
Introduction |
A database is 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 and management. This means that, traditionally, the database word suggests that the list must be formally created in human memory, on a piece of paper, or on a computer file, etc. 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, and so on. Because of this, before creating a list, you should first plan it by deciding what kinds of items would compose the list. |
An item that is part of a list is called datum, with the plural being data, but data can also be used for singular. The group of items, or data, that makes up a list is referred to as a set of data.
To support the creation and management of a set of data, 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 four constructors, the first of which is the default, meaning it does not 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: Public Class Exercise Private Sub btnDocument_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles btnDocument.Click Dim dsVideoCollection As DataSet = New DataSet End Sub End Class 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: Public Class Exercise Private dsVideoCollection As DataSet Private Sub btnDocument_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles btnDocument.Click dsVideoCollection = New DataSet End Sub End Class To visually assist you with creating a data set, in its Data section, the Toolbox provides the DataSet object. Therefore, to visually start creating a data set, you can click DataSet and click the form. When you do this, the Add Dataset dialog box would come up. You must click the Untyped Dataset radio button: Then click OK. After doing it, the compiler would programmatically declare a variable and give its name in the (Name) field of the Properties window.
When creating a set of data, you must name it. This would allow you to refer to the set later on by a formal name. If you create a data set using the DataSet's default constructor, the compiler would give it a default name. To support the data set's object name, the DataSet class is equipped with a property named DataSetName. Therefore, if you create a data set using the class's default constructor, to give it a name, you can assign a string to the DataSetName property. If you visually create a data set, the Microsoft Visual Studio would create a default name for it in the DataSetName field of the Properties windows. If you want to change that name, replace that property's value. To specify a data set's name when creating it, you can use the following constructor of the DataSet class: Public Sub New(dataSetName As String) 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: Public Class Exercise Private dsVideoCollection As DataSet Private Sub btnDocument_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles btnDocument.Click dsVideoCollection = New DataSet("Videos") End Sub End Class |
|
||
Home | Copyright © 2008-2016, FunctionX, Inc. | Next |
|