Working With DATA SET in C# .net

Ratings:
(4)
Views:409
Banner-Img
  • Share this blog:

 

Working With DATA SET:-

  Screenshot_23  

  1. Data Set is a class, which is a part of the System. Data namespace
  2. Data Set supports connectionless architecture.
  3. Data Set is a collection of Tables.
  4. There will be no live communication between Data Set and Database.
  5. Hence Data Adapters are required to provide communication in between Data Set And Database.
  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 of Relations (Data Relation )
  3. Data Set works with the help of XML (extensible markup language)

  Interested in mastering .NET? Learn more about ".NET Training" in this blog post.

Steps to create a DATA SET:-

  Screenshot_24  

Data Set Ex:

Program to prove that Data set is connections less Collection of tables XML based

  Screenshot_25

  • 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 connectionless, hence the modifications on the data set will not be stored in the database.

25 columns

  1. Command builder is a predefined class that 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. The command builder creates the syntax and needs to be given to Data Adapter.

Screenshot_26  

Command Builder:

  1. GET INSERT COMMAND()
  2. GET UPDATE COMMAND()
  3. GET DELETE COMMAND()

 

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

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

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

  Screenshot_27  

  • 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 ”);

The provider is not required for a 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 “Data Set class Hierarchy”.

  Screenshot_28

DS arrrowTarrrow1000 records

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

[179] [N] 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  

Screenshot_29

  • 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 ();
 }    

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox