C# Language

Introduction to Data Sets

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…

2 min read464 words4 code samples

A Set of Data#

Introduction#

A database is a list of items. The exact kind of items does not matter, because any collection of items can form a database. The purpose of treating it as a database is to organize and manage it more effectively. Traditionally, the word database suggests that the list is created in human memory, on paper, or in a computer file. Any kind of thing can be arranged in a list: people, CDs, countries, and many others. For that reason, before you create a list, you should plan what items it will contain. A single item in a list is called a datum, with data as the plural, although data is also used for the singular form. The collection of items, or data, that forms a list is called a set of data.

Data Set Creation#

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 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:

C#
using System;
using System.Data;

public class VideoCollection
{
    public VideoCollection()
    {
        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:

C#
using System;
using System.Data;

public class VideoCollection
{
    public DataSet dsVideoCollection;

    public VideoCollection()
    {
        dsVideoCollection = new DataSet();
    }
}

The third constructor is not used in your applications. The DataSet variable name, in this case dsVideoCollection, is a Windows name that lets the operating system identify the DataSet. That name is required, as is the case for every variable you declare. The DataSetName value is optional, but it is useful in many methods, as we will see. If you do not specify it, the compiler creates a default name for the DataSet object.

C#
public DataSet(string dataSetName);

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:

C#
using System;
using System.Data;

public class VideoCollection
{
    public DataSet dsVideoCollection;

    public VideoCollection()
    {
        dsVideoCollection = new DataSet("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. Home Copyright © 2008 C# Key Next