Professional Documents
Culture Documents
Data Providers
Data Providers
Agenda
Creating Command Object Executing a Command That Doesn't Return Rows. Executing a Command That Returns a Single Value. Parameterized Command Using DataReader Object Transactions Transaction Demo.
.NET Data Providers Connecting to Data Base (SQL Server) Properties and Methods of the SqlConnection Class Storing Connection Strings in the Configuration File Using Command Object
Introduction to ADO.NET
ADO.NET is a data-access subsystem in the Microsoft .NET Framework. ADO.NET was developed from ADO (ActiveX Data Objects). In the .NET Framework, the ADO.NET libraries appear under the System.Data namespace.
ADO.NET Architecture
Objects in ADO.NET
Connected Objects
Disconnected Objects
The .NET data provider is the managed component of choice for database vendors to expose their data in the most effective way. Each database vendor should provide a .NET-compatible API that is callable from within managed applications. The Data Provider is responsible for providing and maintaining the connection to the database.
(OR)
SqlConnection testConnection = new SqlConnection(); string testConnectionString = "Data Source=(local);Initial Catalog=Test;Integrated Security=SSPI"; testConnection.ConnectionString = testConnectionString;
For each connection string in the application, add a new <add> element to the <appSettings> element in the configuration file, as follows:
The classes for accessing the configuration file are found in the System.Configuration namespace. Code below creates connection using connection string stored in configuration file
SqlConnection MyConnection; MyConnection = new SqlConnection(); MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings[constring].ConnectionString;
The Command object is the heart of data processing with ADO.NET. The Command object wraps a SQL statement or a call to a stored procedure. Properties and Methods of the SqlCommand Class
Parameterized Command
The SqlDataReader class defines a lightweight yet powerful object that is used to read information from a SQL database. SqlDataReader retrieves query results in a read-only, forward-only stream of information and will not let you perform updates.
The following code snippet illustrates the typical loop you implement to read all the records of a query:
Thank You