System.Data Namespace
Provides classes that represent the.NET Framework's dataset, which is an in-memory cache of data that can be used to retrieve data from and send data to a data source independently of the data source itself.
Classes
Classes
- DataTable Represents a table of data in a DataSet.
- DataSet Represents a collection of tables, relationships, and constraints for data.
- DataColumn Represents a column in a DataTable.
- DataRow Represents a row of data in a DataTable.
- IDbConnection Represents a connection to a data source.
- IDbCommand Represents a command that can be executed against a data source.
- SqlConnection Represents a connection to a Microsoft SQL Server database.
- SqlDataAdapter Represents a data access object that fills a DataSet and performs operations on a data source.
Enums
Enums
- CommandBehavior Specifies constants that define the behavior of the ExecuteReader, ExecuteNonQuery, and ExecuteXmlReader methods.
- ConnectionState Indicates the state of the connection.
Related Topics
Example: Creating and Populating a DataTable
using System; using System.Data; public class Example { public static void Main() { // Create a new DataTable. DataTable table = new DataTable("Customers"); // Declare DataColumns and add them to the DataTable. DataColumn idColumn = new DataColumn(); idColumn.DataType = typeof(Int32); idColumn.ColumnName = "CustomerID"; idColumn.ReadOnly = true; table.Columns.Add(idColumn); DataColumn nameColumn = new DataColumn(); nameColumn.DataType = typeof(String); nameColumn.ColumnName = "CustomerName"; table.Columns.Add(nameColumn); // Create DataRow objects and add them to the DataTable. DataRow row = table.NewRow(); row["CustomerID"] = 1; row["CustomerName"] = "Customer A"; table.Rows.Add(row); row = table.NewRow(); row["CustomerID"] = 2; row["CustomerName"] = "Customer B"; table.Rows.Add(row); // Print the DataTable. Console.WriteLine("DataTable Name: " + table.TableName); foreach (DataRow dataRow in table.Rows) { Console.WriteLine("ID: {0}, Name: {1}", dataRow["CustomerID"], dataRow["CustomerName"]); } } }