i

ASP.Net A Complete Guide

DataSets and Disconnected Access

It provides a systematic way to deal with disconnected data, and that is entirely independent of the data source. DataSet can be modified offline with the data source through the DataAdapter.The DataSet is an in-memory relational database. It serves as a container for the DataTable, DataColumn, DataRow.

DataSet Synatax:

SqlDataAdapter dataAdapter = new SqlDataAdapter("Select * from student", con); 

                DataSet dataSet = new DataSet(); 

                dataAdapter.Fill(dataSet);

 

Example:

public partial class DataSetTest : System.Web.UI.Page 

    { 

        protected void Page_Load(object sender,  EventArgs e) 

        { 

            using (Sqlconnectionnection connection = new Sqlconnectionnection("data source=.; database=student; integrated security=SSPI")) 

            { 

                SqlDataAdapter dataAdapter = new SqlDataAdapter("Select * from Employee", connection); 

                DataSet dataSet = new DataSet(); 

                dataAdapter.Fill(dataSet);

    // Write code here to bind the data to the controler.

            } 

        } 

    } 

 

 

DataSet Constructors:

DataSet(String):Used to initialize a instance of a DataSet.

DataSet Properties:

  • Tables Used to get the tables contained in the DataSet.

  • HasErrors Used to check whether there are errors in any of the DataTable objects.

DataSet Methods:

  • Reset() This removes all the relations of tables from the DataSet.

  • Clear() This clear the DataSet by removing all rows from all the tables.

  • Clone() This copies the structure of the DataSet.

  • Copy() This copy both the structure & data for this DataSet.