Share Blog

Wednesday, May 14, 2014

DATASET

DataSet has been designed for an offline container that means it always works on disconnected mode.ADO.net dataset contains data tables collections and their relationships it represent a complete set of data including tables that contain tables rows and constraints. Build and fill each data table in a dataset with data from a data source using data adapter.
Dataset is the collection of the DataTable as figure:
The following example shows DataAdapter 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 dataset object
DataSet ds=new DataSet();
ad.fill(ds)//use dataadapter to fill data table
 //close the connection

con.Open();

No comments:

Post a Comment