SlideShare a Scribd company logo
1 of 4
Download to read offline
ADO.NET:
Ado.NET act like a bridge between front end and back end database. See the below diagram.
Now Ado.NET has some class and objects. See below diagram.
DataSet Class:
Dataset class is called subset of database. But it is not actual database. When we want some data from
database we use dataset class.
But we do not directly connect database through dataset. We need some kind of adapter.
When we have connection through dataset (actually through data adapter) and we want to add some
data into table we need table.
DataTable Class:
The data table class represents the tables in the database. We use data row class to add row in the
table.
Finally we have some data and by using some properties we like add etc.. We enter data into table. But
remember this data is not permanently stored in database. Then how to add data permanently in
database. We talk later on this topic. This lesson is just for knowhow from ADO.NET.
See the below code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ADO.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView runat="server" ID="GridView1">
</asp:GridView>
</div>
</form>
</body>
</html>
And the code behind this.
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Make database, we know dataset is subset of database so we use dataset
object
DataSet ds = CreateDataSet();
GridView1.DataSource = ds.Tables["Students"];
GridView1.DataBind();
}
}
private DataSet CreateDataSet()
{
// Create object of dataset
DataSet dataset = new DataSet();
//create table e.g. student, we know class datatable hace table so we use
object
// of datatable
DataTable Students = CreateStudentTable();
//add this table to dataset
dataset.Tables.Add(Students);
return dataset;
}
private DataTable CreateStudentTable()
{
// first of all access Students table
DataTable Students = new DataTable("Students");
// Add columns
AddNewColumn(Students, "System.Int32", "StudentID");
AddNewColumn(Students, "System.String", "StudentName");
AddNewColumn(Students, "System.String", "StudentCity");
// Add rows
AddNewRow(Students, 1, "Salman Mushtaq" , "Lahore");
AddNewRow(Students, 2, "Farzan Mehdi", "Lahore");
AddNewRow(Students, 3, "Umer Farooq", "Lahore");
return Students;
}
private void AddNewColumn(DataTable Students,string columnType, string columnName)
{
DataColumn column = Students.Columns.Add(columnName, Type.GetType(columnType)
);
}
private void AddNewRow(DataTable Students, int id, string name, string city)
{
DataRow row = Students.NewRow();
row["StudentID"] = id;
row["StudentName"] = name;
row["StudentCity"] = city;
Students.Rows.Add(row);
}
}
So what this code said.
First see output of this code.
 The application first creates a data set and binds it with the grid view control using the
DataBind() method of the GridView control.
 The Createdataset() method is a user defined function, which creates a new DataSet
object and then calls another user defined method CreateStudentTable() to create the
table and add it to the Tables collection of the data set.
 The CreateStudentTable() method calls the user defined methods AddNewColumn() and
AddNewRow() to create the columns and rows of the table as well as to add data to the
rows.
Hope you understand.
Refernce: www.tutorialpoint.com

More Related Content

What's hot

Data structures Lecture no.3
Data structures Lecture no.3Data structures Lecture no.3
Data structures Lecture no.3AzharIqbal710687
 
Session 8 Bai 8 ve winform
Session 8 Bai 8 ve winformSession 8 Bai 8 ve winform
Session 8 Bai 8 ve winformmrtom16071980
 
Data structures Lecture no. 2
Data structures Lecture no. 2Data structures Lecture no. 2
Data structures Lecture no. 2AzharIqbal710687
 
Data structures lectures no 1
Data structures lectures no 1Data structures lectures no 1
Data structures lectures no 1AzharIqbal710687
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisationMuzamil Hussain
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureadeel hamid
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)ShrushtiGole
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data StructureMandavi Classes
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURERohit Rai
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization Uma mohan
 
Introduction To Data Structures.
Introduction To Data Structures.Introduction To Data Structures.
Introduction To Data Structures.Education Front
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechniclavparmar007
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureVivek Kumar Sinha
 
Preparing for BIT – IT2301 Database Management Systems 2001e
Preparing for BIT – IT2301 Database Management Systems 2001ePreparing for BIT – IT2301 Database Management Systems 2001e
Preparing for BIT – IT2301 Database Management Systems 2001eGihan Wikramanayake
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 

What's hot (20)

Data structures Lecture no.3
Data structures Lecture no.3Data structures Lecture no.3
Data structures Lecture no.3
 
Session 8 Bai 8 ve winform
Session 8 Bai 8 ve winformSession 8 Bai 8 ve winform
Session 8 Bai 8 ve winform
 
Data structures Lecture no. 2
Data structures Lecture no. 2Data structures Lecture no. 2
Data structures Lecture no. 2
 
Data structures lectures no 1
Data structures lectures no 1Data structures lectures no 1
Data structures lectures no 1
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)
 
Data struters
Data strutersData struters
Data struters
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data Structure
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Data Structure - Elementary Data Organization
Data Structure - Elementary  Data Organization Data Structure - Elementary  Data Organization
Data Structure - Elementary Data Organization
 
Introduction To Data Structures.
Introduction To Data Structures.Introduction To Data Structures.
Introduction To Data Structures.
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
weka data mining
weka data mining weka data mining
weka data mining
 
Data structures notes
Data structures notesData structures notes
Data structures notes
 
Preparing for BIT – IT2301 Database Management Systems 2001e
Preparing for BIT – IT2301 Database Management Systems 2001ePreparing for BIT – IT2301 Database Management Systems 2001e
Preparing for BIT – IT2301 Database Management Systems 2001e
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 

Viewers also liked

Viewers also liked (9)

A Reforma Protestante
A Reforma ProtestanteA Reforma Protestante
A Reforma Protestante
 
Para bond
Para bondPara bond
Para bond
 
Tipografia 2
Tipografia 2Tipografia 2
Tipografia 2
 
單疑點的單點突破術
單疑點的單點突破術單疑點的單點突破術
單疑點的單點突破術
 
Rojas hernandezpractica2
Rojas hernandezpractica2Rojas hernandezpractica2
Rojas hernandezpractica2
 
AF Global Audit Report
AF Global Audit ReportAF Global Audit Report
AF Global Audit Report
 
trabajo de word del desarrollo humano
trabajo de word del desarrollo humanotrabajo de word del desarrollo humano
trabajo de word del desarrollo humano
 
Catalogue 2016-17
Catalogue 2016-17Catalogue 2016-17
Catalogue 2016-17
 
Transporte internacional
Transporte internacionalTransporte internacional
Transporte internacional
 

Similar to ADO DOT NET

Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETEverywhere
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorialinfo_zybotech
 
Disconnected data
Disconnected dataDisconnected data
Disconnected dataaspnet123
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.netSireesh K
 
Ado.net session07
Ado.net session07Ado.net session07
Ado.net session07Niit Care
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxfacebookrecovery1
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenSony Suci
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdfvinaythemodel
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database TutorialPerfect APK
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
React table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilterReact table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilterKaty Slemon
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 

Similar to ADO DOT NET (20)

Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
Android database tutorial
Android database tutorialAndroid database tutorial
Android database tutorial
 
Disconnected data
Disconnected dataDisconnected data
Disconnected data
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Spsl vi unit final
Spsl vi unit finalSpsl vi unit final
Spsl vi unit final
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Ado.net with asp.net
Ado.net with asp.netAdo.net with asp.net
Ado.net with asp.net
 
Ado.net session07
Ado.net session07Ado.net session07
Ado.net session07
 
Csharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptxCsharp_dotnet_ADO_Net_database_query.pptx
Csharp_dotnet_ADO_Net_database_query.pptx
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
React table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilterReact table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilter
 
MAD UNIT 5 FINAL.pptx
MAD UNIT 5 FINAL.pptxMAD UNIT 5 FINAL.pptx
MAD UNIT 5 FINAL.pptx
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 

More from Salman Mushtaq

More from Salman Mushtaq (7)

Bootstrap 3 Lecture 5
Bootstrap 3 Lecture 5Bootstrap 3 Lecture 5
Bootstrap 3 Lecture 5
 
LINQ to SQL
LINQ to SQLLINQ to SQL
LINQ to SQL
 
Captcha
CaptchaCaptcha
Captcha
 
Contact Book Version 1.0
Contact Book Version 1.0Contact Book Version 1.0
Contact Book Version 1.0
 
Entity frame work by Salman Mushtaq -1-
Entity frame work by Salman Mushtaq -1-Entity frame work by Salman Mushtaq -1-
Entity frame work by Salman Mushtaq -1-
 
Database By Salman Mushtaq
Database By Salman MushtaqDatabase By Salman Mushtaq
Database By Salman Mushtaq
 
Serialization
SerializationSerialization
Serialization
 

ADO DOT NET

  • 1. ADO.NET: Ado.NET act like a bridge between front end and back end database. See the below diagram. Now Ado.NET has some class and objects. See below diagram. DataSet Class: Dataset class is called subset of database. But it is not actual database. When we want some data from database we use dataset class. But we do not directly connect database through dataset. We need some kind of adapter. When we have connection through dataset (actually through data adapter) and we want to add some data into table we need table. DataTable Class: The data table class represents the tables in the database. We use data row class to add row in the table.
  • 2. Finally we have some data and by using some properties we like add etc.. We enter data into table. But remember this data is not permanently stored in database. Then how to add data permanently in database. We talk later on this topic. This lesson is just for knowhow from ADO.NET. See the below code. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ADO.NET</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView runat="server" ID="GridView1"> </asp:GridView> </div> </form> </body> </html> And the code behind this. using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Make database, we know dataset is subset of database so we use dataset object DataSet ds = CreateDataSet(); GridView1.DataSource = ds.Tables["Students"]; GridView1.DataBind(); } } private DataSet CreateDataSet() { // Create object of dataset DataSet dataset = new DataSet();
  • 3. //create table e.g. student, we know class datatable hace table so we use object // of datatable DataTable Students = CreateStudentTable(); //add this table to dataset dataset.Tables.Add(Students); return dataset; } private DataTable CreateStudentTable() { // first of all access Students table DataTable Students = new DataTable("Students"); // Add columns AddNewColumn(Students, "System.Int32", "StudentID"); AddNewColumn(Students, "System.String", "StudentName"); AddNewColumn(Students, "System.String", "StudentCity"); // Add rows AddNewRow(Students, 1, "Salman Mushtaq" , "Lahore"); AddNewRow(Students, 2, "Farzan Mehdi", "Lahore"); AddNewRow(Students, 3, "Umer Farooq", "Lahore"); return Students; } private void AddNewColumn(DataTable Students,string columnType, string columnName) { DataColumn column = Students.Columns.Add(columnName, Type.GetType(columnType) ); } private void AddNewRow(DataTable Students, int id, string name, string city) { DataRow row = Students.NewRow(); row["StudentID"] = id; row["StudentName"] = name; row["StudentCity"] = city; Students.Rows.Add(row); } } So what this code said. First see output of this code.
  • 4.  The application first creates a data set and binds it with the grid view control using the DataBind() method of the GridView control.  The Createdataset() method is a user defined function, which creates a new DataSet object and then calls another user defined method CreateStudentTable() to create the table and add it to the Tables collection of the data set.  The CreateStudentTable() method calls the user defined methods AddNewColumn() and AddNewRow() to create the columns and rows of the table as well as to add data to the rows. Hope you understand. Refernce: www.tutorialpoint.com