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.
SqlConnection con = new SqlConnection("server=abc-pc1\\sqlexpress; uid=sa; password=sa; database=mind");
//open connection
con.Open();
//create a data adapter and invoking the command.
SqlDataAdapter ad = new SqlDataAdapter("select * from Employee", con);
//creating dataset object
DataSet ds=new DataSet();
ad.fill(ds)//use dataadapter to fill data table
//close the connection
con.Open();
Leave Comment
2 Comments