Home

The Records of a Table

 

Introduction to Records

In our description of tables, we saw that a table was made of one or various columns that represented some categories of data. Here is an example of a table with a few columns:

using System;
using System.Data;

namespace VideoCollection
{
    public static  class Program
    {
        static DataSet dsVideos;

        static DataColumn colShelfNumber;
        static DataColumn colTitle;
        static DataColumn colDirector;
        static DataColumn colLength;
        static DataColumn colYear;
        static DataColumn colRating;
        static DataTable tblVideos;

        static void CreateCollection()
        {
            dsVideos = new DataSet("Videos");

            tblVideos = new DataTable("Video");

            colShelfNumber = new DataColumn("ShelfNumber",
                                     Type.GetType("System.String"));
            tblVideos.Columns.Add(colShelfNumber);

            colTitle = new DataColumn("Title",
                Type.GetType("System.String"));
            tblVideos.Columns.Add(colTitle);

            colDirector = new DataColumn("Director",
                                         Type.GetType("System.String"));
            tblVideos.Columns.Add(colDirector);

            colLength = new DataColumn("Length",
                                       Type.GetType("System.String"));
            tblVideos.Columns.Add(colLength);

            colYear = new DataColumn("Year",
                                       Type.GetType("System.Int16"));
            tblVideos.Columns.Add(colYear);

            colRating = new DataColumn("Rating",
                                       Type.GetType("System.String"));
            tblVideos.Columns.Add(colRating);

            dsVideos.Tables.Add(tblVideos);
        }

        static int Main(string[] args)
        {
            CreateCollection();

            return 0;
        }
    }
}

After creating such a table and its columns, you (actually the user) can enter values in the table to make it a valuable list. Filling up a table with values is referred to as data entry.

Practical Learning Practical Learning: Introducing Data Records

  1. Start Microsoft Visual C# and create a Console Application named CollegeParkAutoParts4
  2. To save the application, on the Standard toolbar, click the Save All button
  3. Accept all defaults and click Save

The Row of a Table

A record on a table is represented as a row (horizontal) of data. A row, or record, is an object based on the DataRow class.

To support the various records that belong to a table, the DataTable class is equipped with a property called Rows. The DataTable.Rows property is an object of the DataRowCollection class. The DataRowCollection class provides the necessary properties and methods you can use to create and manage records of a table. 

Introduction to Data Entry

When performing data entry and while doing it on a record, the record has a status that can be identified by the DataRow.RowState property which is a value based on the DataRowState enumerator.

A record on a table is represented as a row of data. To support the various records that belong to a table, the DataTable class is equipped with the Rows property which is an object of type DataRowCollection with each record being an object of type DataRow.

Before adding a new record to a table, you must let the table know. This is done by calling the DataTable.NewRow() method. Its syntax is:

public DataRow NewRow();

The DataTable.NewRow() method returns a DataRow object. Here is an example of calling it:

using System;
using System.Data;

namespace VideoCollection
{
    public static  class Program
    {
        . . . No Change

        static void CreateRecord()
        {
            DataRow rowVideo = tblVideos.NewRow();
        }

        static int Main(string[] args)
        {
            return 0;
        }
    }
}

 

 

Previous Copyright © 2006-2016, FunctionX, Inc. Next