Thursday, 27 June 2013

Use of data adapter.

The use of data adapter.?

data adapter:-The DataAdapter serve as a bridge between a DataSet and data source for retrieving and saving data. The DataAdapter provides this bridge by using Fill to load data from the data source into the DataSet and using Update to send changes made in the DataSet back to the data source.  The data adapter objects connect a command objects to a Dataset object. They provide the means for the exchange of data between the data store and the tables in the DataSet.An OleDbDataAdapter object is used with an OLE-DB provider
A SqlDataAdapter object uses Tabular Data Services with MS SQL Server
.

Namespace:  System.Data.Common

Assembly:  System.Data (in System.Data.dll)
Data adapter Flow  Architecture
The DataAdapter acts as a bridge between the disconnected DataSet and the data source. It exposes two interfaces; the first of these,IDataAdapter that  defines methods for populating a DataSet with data from the data source and for updating the data source with changes made to the DataSet on the client. The another interface is  IDbDataAdapter that  defines four properties, each of type IDbCommand. These all properties each set or return a command object specifying the command to be executed when the data source is to be queried or updated:



There are two constructor:

Name
Description
DataAdapter(DataAdapter)Initializes a new instance of a DataAdapter class from an existing object of the same type.
DataAdapterInitializes a new instance of a DataAdapter class.
Property  of Data Adapter?
there are following main property:
                                              Name          Description
TableMappingsGets a collection that provides the master mapping between a source table and a DataTable.
ContainerGets the IContainer that contains the Component. (Inherited from Component.)
DesignModeGets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
EventsGets the list of event handlers that are attached to this Component. (Inherited from Component.)
Gets or sets whether AcceptChanges is called during aUpdate.
 AcceptChangesDuringFillGets or sets a value indicating whetherAcceptChanges is called on a DataRow after it is added to the DataTable during any of the Filloperations.
Method  of Data Adapter?
there are following main method:-
                                                               Name                                                    Description
Dispose                                     Releases all resources used by the Component(Inherited fromComponent.)                                     
Fill(DataSet)Adds or refreshes rows in the DataSet to match those in the data source.
FinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
GetTypeGets the Type of the current instance. (Inherited fromObject.)
Event of Data Adapter?
There are two events:-
NameDescription
DisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)
FillErrorReturned when an error occurs during a fill operation.
 Interface Implementation of Data Adapter?
NameDescription
IDataAdapter.TableMappingsIndicates how a source table is mapped to a dataset table.
Basic method of Data Adapter?
There are three basic method in data adopter:-
(i)Fill:-Fill  method executes the SelectCommand to fill the DataSet object with data from the data source,Depending on whether there is a primary key in the DataSet, the ‘fill’ can also be used to update an existing table in a DataSet with changes made to the data in the original datasource.
(ii)FillSchema:-Fill Schema method executes the SelectCommand to extract the schema of a table from the data source and  creates an empty table in the DataSet object with all the corresponding constraints.
(iii0Update:-Update method executes the InsertCommand, UpdateCommand, or DeleteCommand to update the original data source with the changes made to the content of the DataSet.
(iv) Dispose :- releases all the resources

No comments: