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
ClassRepresents an in-memory cache of data that can be treated as a relational database table.
-
DataColumn
ClassRepresents a column in a
DataTable
. -
DataRow
ClassRepresents a single row of data in a
DataTable
. -
DataSet
ClassRepresents a collection of
DataTable
objects that, when taken together, provide a consistent relational view of data. -
DbConnection
ClassRepresents a connection to a data source.
-
DbCommand
ClassRepresents an abstract command to execute against a data source.
Interfaces
-
IDataReader
InterfaceProvides access to the rows in a data source.
-
IDbTransaction
InterfaceRepresents a transaction to be performed at a data source.
Enums
-
CommandBehavior
EnumSpecifies options for executing a
Command
.
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"]}");
}
}
}