Share Blog

Wednesday, May 14, 2014

DATA ADAPTER

Data Adapter serves a bridge between dataset and data source for retrieving and saving data from the database. The data Adapter provides this bridge by mapping fill which changes the data in dataset to make the data in data source.
Data Adapters can be created by using;
·         Data Adapters wizards
·         Using solution explorer.
·         Using .net classes in the code

Data Adapters is a powerful tools which:

·         Creates data connection
·         Invoke the command
·         Fill the dataset in asp.net application with data from database.


Data Adapter has following properties to execute the records from the database like Select Command, Insert Command, and Delete Command.

The following example shows data Adapter in c#.

//these lines are for creating a new connection by passing server name,uid,password and name of the database as here mind.

//Below variable holds the Connection String.
 SqlConnection con = new SqlConnection("Data Source=SUNIL;Initial Catalog=adonetpractices;Integrated Security=True");
//open connection      
con.Open();
//create a data adapter and invoking the command.
SqlDataAdapter ad = new SqlDataAdapter("select * from Emp", con);
//creating datatable object 
Datatable dt = new DataTable();
//use dataadapter to fill data table
ad.Fill(dt);
  //close the connection

con.Open();

No comments:

Post a Comment