System.Data Namespace

This namespace provides access to the Windows Forms, Windows, and Visual Basic namespaces.

Note: This documentation may refer to namespaces and types that are not part of the core .NET Framework, but are specific to certain environments like Windows Forms or older Visual Basic projects.

Classes

  • DataTable

    Class

    Represents an in-memory cache of data that can be treated as a relational database table.

  • DataColumn

    Class

    Represents a column in a DataTable.

  • DataRow

    Class

    Represents a single row of data in a DataTable.

  • DataSet

    Class

    Represents a collection of DataTable objects that, when taken together, provide a consistent relational view of data.

  • DbConnection

    Class

    Represents a connection to a data source.

  • DbCommand

    Class

    Represents an abstract command to execute against a data source.

Interfaces

  • IDataReader

    Interface

    Provides access to the rows in a data source.

  • IDbTransaction

    Interface

    Represents a transaction to be performed at a data source.

Enums

Related Topics

Example Usage

// Example of creating and populating a DataTable
using System.Data;

public class DataExample
{
    public static void Main(string[] args)
    {
        DataTable table = new DataTable("MyTable");

        // Add columns
        DataColumn idColumn = new DataColumn("ID", typeof(int));
        DataColumn nameColumn = new DataColumn("Name", typeof(string));
        table.Columns.Add(idColumn);
        table.Columns.Add(nameColumn);

        // Add rows
        DataRow row1 = table.NewRow();
        row1["ID"] = 1;
        row1["Name"] = "Alice";
        table.Rows.Add(row1);

        DataRow row2 = table.NewRow();
        row2["ID"] = 2;
        row2["Name"] = "Bob";
        table.Rows.Add(row2);

        // Display data
        foreach (DataRow row in table.Rows)
        {
            Console.WriteLine($"ID: {row["ID"]}, Name: {row["Name"]}");
        }
    }
}