Wednesday, March 17, 2010

ADO.NET & Common Code for Connection in VB.NET

ADO.NET was designed to meet the needs of this new programming model: disconnected data architecture, tight integration with XML, common data representation with the ability to combine data from multiple and varied data sources, and optimized facilities for interacting with a database, all native to the .NET Framework.

ADO.NET Components:

ADO.NET Components have been designed to factor data access for data manipulation. There are two central components of ADO.NET that accomplish this is

Dataset &

Data Provider





All the 4 under Data Provider are Data Provider Objects

ADO.NET DataSet: is the core component of the disconnected architecture of ADO.NET. The DataSet is explicitly designed for data access independent of any data source. As a result it can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. The DataSet contains a collection of one or more DataTable objects made up of rows and columns of data, as well as primary key, foreign key, constraint, and relation information about the data in the DataTable objects.

The other core element of the ADO.NET architecture is the, .NET Framework Data Provider whose components are explicitly designed for data manipulation and fast, forward-only, read-only access to data. The Connection object provides connectivity to a data source. The Command object enables access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information. The DataReader provides a high-performance stream of data from the data source. Finally, the DataAdapter provides the bridge between the DataSet object and the data source. The DataAdapter uses Command objects to execute SQL commands at the data source to both load the DataSet with data, and reconcile changes made to the data in the DataSet back to the data source.

You can write .NET Framework data providers for any data source. The .NET Framework ships with two .NET Framework data providers: the .NET Framework Data Provider for SQL Server and the .NET Framework Data Provider for OLE DB.


Imports System.Data.SqlClient

Dim SqlConn As New SqlConnection()

Dim SqlComnd As New SqlCommand()

Dim Sqldr As SqlDataReader

SqlConn.ConnectionString = "DataSource=localhost;Initial Catalog=Audit.mdf;Integrated Security=SSPI;"


SqlComnd.Connection = SqlConn

SqlComnd.CommandText = "Select * From Employee"

Sqldr = SqlComnd.ExecuteReader

While Sqldr.Read()

End While



No comments:

Post a Comment