articles

Home / DeveloperSection / Articles / DataAdapter

DataAdapter

Amit Singh5770 29-Aug-2010

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.

 

SqlConnection con = newSqlConnection("server=abc-pc1\\sqlexpress; uid=sa; password=sa; database=mind");

//open connection      

con.Open();

//create a data adapter and invoking the command.

SqlDataAdapter ad = newSqlDataAdapter("select * from Employee", con);

//creating datatable object 

Datatable dt = new DataTable();

//use dataadapter to fill data table
ad.Fill(dt);

  //close the connection

con.Open();


Updated 30-Nov-2017

Leave Comment

Comments

Liked By