Connectionless Architecture In ADO.NET

Introduction

 
ADO stands for active data objects. It behaves as a mediator between the client-side and the server-side. As we know that one language does not understand the syntax of another language, there will be one translator who will behave as a mediator between both the languages as in the following figure:
 
Translator
 
Figure: Translator
 
The above figure has shown there are two persons. One person is an English speaker and another is a Hindi speaker so there is a translator who will help both the persons to communicate.
 

Connectionless oriented architecture

 
Connectionless oriented architecture contains:
  • Connection
  • DataAdapter
  • DataSet
Connection: Connection class uses to establish the connection between the front end and back end.
  1. SqlConnection con=new SqlConnection(“integratd security=true;initial catalog=Table Name;data source=.”);  
DataAdapter: DataAdapter behaves as a mediator between data source and table.
  1. SqlDataAdapter da=new SqlDataAdapter(“Query which has to excute”,Connection object);  
DataSet: DataSet contains the tables and relationships as in the following figure:
 
Connection less architecture
 
Figure: Connectionless architecture
 
DataAdapter does not have a feature of containing data so there is a dataset that contains table and relation after generating result set.
 
Syntax for DataSet is:
 
DataSet ds=new DataSet();
Da.Fill(ds,”X”);
 
The architecture of connectionless is as in the following figure:
 
Client-side interacts with server-side through ADO.NET because the front end application will not understand the syntax of back end application so there is ADO.NET which is a group of classes that contain Connection, Command, DataAdapter, and DataSet.
 
SSMS
 
Figure: Connectionless architecture
 
For performing work with connectionless architecture:
  • Work on the back end.
     
  • Go to the start button.
     
  • Select the SQL Server Management Studio.
     
  • Click on SSMS.
     
    Here's the figure:
     
    create table
     
  • Go to object explorer.
     
  • Select Database.
     
  • Create database.
     
    Now create the table in the newly created database. After creating the database go to object explorer.
     
  • Go to the database.
     
    Select the database then select table as in the following figure:
     
    select table
     
  • Now insert the data in table by using the following query:
    1. insertinto Emp values(1,'Sandeep',20000,'Y')  
    2. insertinto Emp values(2,'Mukesh',20000,'Y')  
    3. insertinto Emp values(3,'Rakesh',30000,'N')  
    4. insertinto Emp values(4,'Pappu',35000,'Y')  
    5. insertinto Emp values(5,'Dinesh',25000,'Y')  
    6. insertinto Emp values(6,'Munna',28000,'N')  
    7. insertinto Emp values(7,'Prakash',3200,'Y')  
    Now run the query: Select * from Emp which will generate output as in the following figure:
     
    output
     
  • Work on the front end.
     
  • Go to Visual Studio.
Create one web application now go to the .aspx page and write the following code for design:
  1. <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="DataList.aspx.cs"Inherits="IARE_Bus.DataList"%>  
  2. <!DOCTYPE html>  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4.   
  5.     <head runat="server">  
  6.         <title></title>  
  7.     </head>  
  8.   
  9.     <body>  
  10.         <form id="form1" runat="server">  
  11.             <div>  
  12.                 <asp:DataListIDasp:DataListID="DataList1"runat="server"OnSelectedIndexChanged="DataList1_SelectedIndexChanged">  
  13.                     <HeaderTemplate>  
  14.                         StartingPoint EndPoint Via Driver Bus_No  
  15.                     </HeaderTemplate>  
  16.                     <ItemTemplate>  
  17.                         <%#Eval("StartingPoint") %                               >      
  18.                             <%#Eval("EndingPoint") %>  
  19.                         <%#Eval("Via") %>  
  20.                         <%#Eval("Driver") %>  
  21.                         <%#Eval("Bus_No") %>  
  22.                     </ItemTemplate>  
  23.                     </asp:DataList>  
  24.             </div>  
  25.         </form>  
  26.     </body>  
  27.   
  28. </html> 
The design of the web application will be the following:
 
design
 
Now go to aspx.cs and write the following code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data;  
  8. using System.Data.SqlClient;  
  9. namespace IARE_Bus {  
  10.     public partial class DataList: System.Web.UI.Page {  
  11.         SqlConnection con = newSqlConnection("integrated security=true;initial catalog=Iare;data source=.");  
  12.         SqlDataAdapter da;  
  13.         protected void Page_Load(object sender, EventArgs e) {  
  14.             string s = "select * from BusInfo";  
  15.             da = newSqlDataAdapter(s, con);  
  16.             DataSet ds = newDataSet();  
  17.             da.Fill(ds, "Bus");  
  18.             DataList1.DataSource = ds.Tables[0];  
  19.             DataList1.DataBind();  
  20.         }  
  21.   
  22.         protected void DataList1_SelectedIndexChanged(object sender, EventArgs e) {  
  23.   
  24.         }  
  25.     }  
Now run the application and check. In datalist all details of BusInfo table will display.
 
Read more articles on ADO.NET: