Connectionless Architecture In ADO.NET

Introduction

ADO stands for active data object. It behaves as a mediator between the client side and server side. As we know that one language does not understand the syntax of other language, there will be one translator who will behave as 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.

Connection less oriented architecture

Connection less oriented architecture contains:

  • Connection
  • DataAdapter
  • DataSet

Connection

Connection class use to establish the connection between front end and back end.

  1. SqlConnection con=new SqlConnection(“integratd security=true;initial catalog=Table Name;data source=.”);  
DataAdapter: DataAdapter behave 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 relation as in the following figure:

Connection less architecture
               Figure: Connection less architecture

DataAdapter does not have a feature of containing data so there is a dataset which contains table and relation after generating result set.

Syntax for DataSet is:

DataSet ds=new DataSet();
Da.Fill(ds,”X”);


The architecture of connection less is as in the following figure:

Client side interacts with server side through ADO.NET because front end application will not understand syntax of back end application so there is ADO.NET which is group of classes that contain Connection, Command, DataAdapter, and DataSet.

SSMS
                                 Figure: Connection less architecture

For performing work with connection less architecture:
  • Work on back end.

  • Go to start button.

  • Select 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 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 front end.

  • Go to Visual Studio.

Create one web application now go to .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.     <head runat="server">  
  5.         <title></title>  
  6.     </head>  
  7.     <body>  
  8.         <form id="form1"runat="server">  
  9.             <div>  
  10.                 <asp:DataListID="DataList1"runat="server"OnSelectedIndexChanged="DataList1_SelectedIndexChanged">  
  11.                     <HeaderTemplate>  
  12. StartingPoint  EndPoint   Via    Driver   Bus_No  
  13. </HeaderTemplate>  
  14.                     <ItemTemplate><%#Eval("StartingPoint") %                               >    
  15.                         <%#Eval("EndingPoint") %>    
  16.                         <%#Eval("Via") %>    
  17.                         <%#Eval("Driver") %>    
  18.                         <%#Eval("Bus_No") %>  
  19.                     </ItemTemplate>  
  20.                 </asp:DataList>  
  21.             </div>  
  22.         </form>  
  23.     </body>  
  24. </html>  
The design of 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. {  
  11. public partial class DataList : System.Web.UI.Page  
  12.     {  
  13. SqlConnection con = newSqlConnection("integrated security=true;initial catalog=Iare;data source=.");  
  14. SqlDataAdapter da;  
  15. protected void Page_Load(object sender, EventArgs e)  
  16.         {  
  17. string s = "select * from BusInfo";  
  18. da = newSqlDataAdapter(s, con);  
  19. DataSet ds = newDataSet();  
  20. da.Fill(ds, "Bus");  
  21.             DataList1.DataSource = ds.Tables[0];  
  22. DataList1.DataBind();  
  23.         }  
  24.   
  25. protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)  
  26.         {  
  27.   
  28.         }  
  29.     }  
  30. }  
Now run the application and check. In datalist all details of BusInfo table will display.
 
Read more articles on ADO.NET: