Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Chapter-4 Working with Data Adapters



Data Adapters

1)      Data adapters are an integral part of ADO.NET managed providers, which are the set of objects used to communicate between a data source and a DataSet
2)      Data adapters forms an interface between the application and the data source from retrieving and saving data.
3)      A data adapter handles data transfer between the Database and the DataSet through its properties and methods, and displays data through the process of table mapping.
4)      A data adapter is integral to the working of ADO.NET because data is transferred to and from a database through a data adapter.
5)      A data adapter retrieves data from a database into a DataSet. 



6)      The data adapter first compares the data in the dataset with that in the database and then updates the database.
7)      Data from a database can be accessed by configuring a data adapter.
8)      Following are the data adapters that can be configured to connect to a database:
a)      SqlDataAdapter: Accesses data specifically from Microsoft SQL Server
b)      OleDbDataAdapter: Accesses data from a database that is supported by an OLE DB data provider. OleDbDataAdapter object represents a connection and a set of command objects that helps populat a Dataset object.
c)       OdbcDataAdapter: Accesses data from a database that is supported by an ODBC data provider
d)      OracleDataAdapter: Accesses data from a database that is supported by an Oracle data provider
9)      The following properties and methods of a data adapter can be used to perform various operations on a database:
a)      SelectCommand: Refers to a DML statement or a stored procedure to retrieve data from a database .You set the CommandText property of Default Command Object is created when you SelectCommand object. It doesnot return any rows , no table to Dataset and no exception is thrown.
b)      InsertCommand: Refers to a data command to insert data into a database .You set the CommandText property of default Command object is created when you insert command object. InsertCommandProperty return an integer value that specifies the number of rows affected by corresponding  insert operation.
c)       UpdateCommand: Refers to a data command to update a database .You set the CommandText property of default Command object is created when you update command object.When you execute the UpdateCommand object, it returns the number of rows affected by update operation.
d)      DeleteCommand: Refers to a data command to delete data from a database.You set the CommandText property of default Command object is created when you delete command object.When you execute the DeleteCommandobject, it returns the number of rows affected by update operation.
e)      Fill(): Fills the dataset with the records from a database
f)       Update(): Executes the corresponding Insert, Update, or Delete commands for each inserted, modified, or deleted row to reflect the changes in a database .Update method to update the database with changes from Dataset object, Update method is usually called from the Page_PreRenderevent procedure.

10)   After a dataset has been created, the data adapter uses the process of table mapping to map the columns in the database table with the dataset columns.
11)   A data adapter uses the TableMappings property, a collection of DatatableMapping objects that is used for mapping between the database table and the DataTable object in the dataset. 

Demo How to use Data Adapter in Asp.net

Steps: 1) Open website in Visual studio .

2) Drag Gridview , Button on web page.

3) Create a store procedure in Sql Server.

create proc pp1
as begin
select * from std
end

4) Write the below code on the button click event in Asp.net

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;

usingSystem.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected voidPage_Load(object sender, EventArgs e)
    {

    }
    protected voidButton1_Click(object sender, EventArgs e)


This post first appeared on Drop IF Exists In SQL SERVER 2016, please read the originial post: here

Share the post

Chapter-4 Working with Data Adapters

×

Subscribe to Drop If Exists In Sql Server 2016

Get updates delivered right to your inbox!

Thank you for your subscription

×