The frequent use of databases in applications requires that the .NET Framework
address the need for APIs that can access the data stored within. Of course, this
has been the case since the first appearance of .NET. The .NET Framework Class
Library (FCL) includes ADO.NET, which provides an API to access relational databases
and to represent relational data in memory. This API consists of classes such
as SqlConnection, SqlCommand, SqlReader, DataSet, and DataTable, to name a
few. You can find the exmaple as below.
address the need for APIs that can access the data stored within. Of course, this
has been the case since the first appearance of .NET. The .NET Framework Class
Library (FCL) includes ADO.NET, which provides an API to access relational databases
and to represent relational data in memory. This API consists of classes such
as SqlConnection, SqlCommand, SqlReader, DataSet, and DataTable, to name a
few. You can find the exmaple as below.
private static void ReadOrderData(string connectionString) { string queryString = "SELECT OrderID, CustomerID FROM dbo.Orders;"; using (SqlConnection connection = new SqlConnection( connectionString)) { SqlCommand command = new SqlCommand( queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1])); } } finally { // Always call Close when done reading. reader.Close(); } } }
Comments
Post a Comment