Working With DATA SET:-




  1. Data Set is a class , which is a part of System. Data name space
  2. Data Set supports connection less architecture.
  3. Data Set is a collection of Tables.
  4. There will be no live communication in between Data Set and Data base.
  5. Hence Data Adapters are required to provide communication in between Data Set And Data base.
  6. Data set holds a collection of tables, where every table contains a unique index number, optionally alias name can be provided.

Select  * from EMP;

  1. Data Set Supports to create constraints like primary and foreign keys.
  2. Data Set supports to create Relations (Data Relation )
  3. Data Set works with the help of XML (extensible markup language)


Steps to create a DATA SET :-




Data Set Ex:

Program to prove that

Data set is connections less

Collection of tables

XML based



  • Open windows Forms Application Project
  • Place four buttons and a Data Grid view control

Using  System . Data. Sql client;

  • Code in GD

Data Set ds = new Data Set ();

  • Code for Button 1_click (get)


Sql connection con = new Sql connection  (“User id = sa;  Password = ; data base = north wind; Server = local Host”) ;

Sql Data Adapter  d1 = new Sql Data Adapter

(“Select * from products” , con);

Sql Data Adapter  d2= new Sql Data Adapter

(“Select * from  orders ” , con);

D1.Fill (ds, “pr”);

D2.Fill (ds,”or”);

Message Box. Show  (“Data is ready”);

Code for Button 2_click (products)


DS----Tables               or 1


Data Grid view 1. Data Source = ds . Tables [“Pr”];  or ds. Tables [0];


Code for Button 3_click (orders)


Data Grid view 1. Data Source = ds . Tables [“or”];  or ds. Tables [1];


  • Code for Button 4_click (XML)


Ds. Write XML (“C: //abc.XML”)

Message Box. Show 1 (“File is created”);



Working with Data Set Manipulations:-

  1. AS Data set is connection less , hence the modifications on the data set will not  be stored in data base.

25 columns

  1. Command builder is a predefined class which helps to create DML statement syntaxes automatically.
  2. Command builder class purpose is to create the syntax only but not to Execute that syntax.
  3. Command builder creates the syntax and which need to be given to Data Adapter.



Command Builder:



Example   on   Command Builder with oracle Data base over Managed Connection (System. Data. Oracle. Client)


Oracle client namespace is not available at the default scope of the project, hence System. Data. Oracle client Assembly need to be added.

  • Open windows Forms Application Project
  • Place two Buttons and a data grid view control.




  • Go to the project menu arrrow Add reference arrrow System.  Data. Oracle client

Using  System . Data. Oracle client

  • Code in GD


Static oracle connection con = new oracle connection (“User id  = Scott; Password = tiger ”);

Provider is not required for managed  connection.

Oracle Data Adapter da = new oracle Data Adapter

(“Select * from c 194”, con);

Data set ds = new Data set ();

Code for Button 1_ click (get)

Da. Fill (ds, “d”);

Data Grid view 1. Data Source = ds .tables [“d”];

Code for Button 2_click  (save)

Oracle command builder cb = new;

Oracle command builder (da);

Message Box. Show (cb. Get Insert  command () )

Da. Insert command = cb. Get Insert command ();

Da. Update (ds, “d”);

Message Box. Show (“Record is Added ”) ;




Data Set class Hierarchy:

A collection of Data set Related classes is called as “Data Set class Hierarchy”.



DS arrrowTarrrow1000 records

  1. R
  2. Table [‘T’] .Row [478]



FIRST N =0;                                              LAST N = DS. Tables [‘T’]. Rows . count -1

Next N = N+1

Previous  N = N-1



A program for navigating through the records



  • open windows Forms Application Project
  • design a Form as shown
  • Using System . Data. Sql client;


Code in GD


Data table dt = new Data Table ();

Int n =0 ;

Public void Show record ()


Data Row dr = dt. Rows [n];

Text Box1.Text = dr [0]. To String ();

Text Box2.Text = dr [1]. To String ();


Code for Form 1_ load Event

Sql Connection con = new sql Connection

(“User id = sa; data base = north wind; Server = Local Host”);

Sql Data Adapter da = new Sql Data Adapter   (“Select  * from Products”, con);

Data set ds = new Data set ();

Da. Fill (ds, “d”);

Dt = ds . Tables [“d”];

// column Names

Label 1 .Text = dt. Columns [0]. Column Name;

Label 2 .Text = dt. Columns [1]. Column Name;

Show Record ();


  • Code for Button 1_ click (<< First Record)


N =0;

Show  Record ();


  • Code for Button2_ click (< Previous record )


N = n -1;

If (n== -1)


Message Box. Show  (“No previous Record ”);

N = 0;


Show Record ();


  • Code for Button 3_click (> Next Record)


N = n+1;

If (n > dt. Rows. Count  -1 )


Message  Box . show (“ No Next Record”);

N = dt. Rows. Count -1;


Show Record ();


  • Code for Butto4_ click (>> last Record)


N = dt. Rows . count – 1;

Show Record ();