System.Data Namespace

Overview

The System.Data namespace provides access to classes that represent the core ADO.NET architecture. It includes base classes for data access, data manipulation, and in-memory data storage.

Common Types

DataSet

Represents an in-memory cache of data retrieved from a data source.

Read more →

DataTable

Represents one table of in-memory relational data.

Read more →

SqlConnection

Establishes a connection to a Microsoft SQL Server database.

Read more →

SqlCommand

Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database.

Read more →

SqlDataAdapter

Fills a DataSet and updates a data source using SQL commands.

Read more →

DataReader

Provides a fast, forward-only way of reading data from a data source.

Read more →

Assembly

Assembly: System.Data.dll

<Reference Include="System.Data" />

Example: Retrieve Data with SqlConnection

// C# Example
using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        var connectionString = "Server=.;Database=Northwind;Trusted_Connection=True;";
        using var conn = new SqlConnection(connectionString);
        conn.Open();

        var cmd = new SqlCommand("SELECT TOP 5 * FROM Customers", conn);
        using var reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine($"{reader["CustomerID"]} - {reader["CompanyName"]}");
        }
    }
}