Connection Oriented Architecture In ADO.NET


ADO stands for active data object, which behaves as a mediator between the client side and server side. Client side can’t directly interact withthe server side, so there is ADO.NET which behaves as a mediator between front end and back end as in the following figure:

                                          Figure: ADO.NET

The preceding image shows the client side application interact with server side application through ADO.NET which is behaving as mediator between front end and back end.

Note: A programming language does not understand syntax and structure of other programming language but if it is required to interact from one to another programming language, there will be one mediator which will help them to interact without any problem.

Connection Oriented in ADO.NET

Before discussing about ADO.NET connection orientation we will discuss what ADO.NET contains.

ADO.NET is a group of class which contains.

  • Connection
  • Command
  • Datareader
  • DataAdapter
  • Dataset


Connection class used to establish the connection between front end and back end:

  1. SqlConnection con=new SqlConnection(“Integrated security=true;initial catalog=Student;Data source=.”);   
  1. SqlConnection Con=new SqlConnection(“User id=sa;Password=sa123;Database=Student;Server=.”);  

Command class behaves as bridge between front end and back end. It contains the query which has to perform from front end and back end and also it contains object of Connection Class:
  1. SqlCommand cmd=new SqlCommand(“Query which has to perform”,Connection Object);  
  • DataReader: DataReader used to read the data from source.
  • Dataset: DataSet contains the table and relation.
  • DataAdapter: DataAdapter behave as mediator between back end and front end. But it does not has features to contains the data .So there is dataset which contains the data of result set.
In connection-oriented architecture the Database gets connected to the front end then the command passes the query to the server from back end and on the server the result which has been generated. The result which has been generated will be read by DataReader. Here's the screenshot:


The above figure has shown that connection oriented architecture of ADO.NET has Connection, Command, and DataReader used to establish the connection between front end and back end, and passing the query from the front end to the back end.

Sample code:

Write the code for design or use drag down to design the application.

  1. <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Student.aspx.cs"Inherits="Iare.Student"%>  
  2. <!DOCTYPE html>  
  3. <html  
  4.     xmlns="">  
  5.     <head runat="server">  
  6.         <title></title>  
  7.         <styletype="text/css">  
  8.           .auto-style1 {  
  9.           width: 100%;  
  10.           }  
  12.         </style>  
  13.     </head>  
  14.     <body style="height: 198px; width: 364px">  
  15.         <form id="form1"runat="server">  
  16.             <table class="auto-style1">  
  17.                 <tr>  
  18.                     <tdcolspan="2">  
  19.                         <asp:DropDownListID="DropDownList1"runat="server"DataSourceID="Iare"DataTextField="SId"DataValueField="SId">  
  20.                         </asp:DropDownList>  
  21.                         <asp:SqlDataSourceID="Iare"runat="server"ConnectionString="<%$ ConnectionStrings:IareConnectionString %>"SelectCommand="SELECT [SId] FROM  [Library]">  
  22.                         </asp:SqlDataSource>  
  23.                     </td>  
  24.                 </tr>  
  25.                 <tr>  
  26.                     <td>  
  27.                         <asp:LabelID="Label1"runat="server"Text="Student First Name Is :">  
  28.                         </asp:Label>  
  29.                     </td>  
  30.                     <td>  
  31.                         <asp:TextBoxID="TextFName"runat="server">  
  32.                         </asp:TextBox>  
  33.                     </td>  
  34.                 </tr>  
  35.                 <tr>  
  36.                     <td>  
  37.                         <asp:LabelID="Label2"runat="server"Text="Student Last Name Is :">  
  38.                         </asp:Label>  
  39.                     </td>  
  40.                     <td>  
  41.                         <asp:TextBoxID="TextLName"runat="server">  
  42.                         </asp:TextBox>  
  43.                     </td>  
  44.                 </tr>  
  45.                 <tr>  
  46.                     <td>  
  47.                         <asp:LabelID="Label3"runat="server"Text="Student Is Study :">  
  48.                         </asp:Label>  
  49.                     </td>  
  50.                     <td>  
  51.                         <asp:TextBoxID="TextCourse"runat="server">  
  52.                         </asp:TextBox>  
  53.                     </td>  
  54.                 </tr>  
  55.                 <tr>  
  56.                     <td>  
  57.                         <asp:LabelID="Lbldsply"runat="server">  
  58.                         </asp:Label>  
  59.                     </td>  
  60.                     <td>  
  61.                         <asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Save"/>  
  62.                     </td>  
  63.                 </tr>  
  64.             </table>  
  65.             <div></div>  
  66.         </form>  
  67.     </body>  
  68. </html>  
Student Application
                                                            Figure: Student Application

After designing the application go to Student.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  
  10. {  
  11.   public partial classStudent : System.Web.UI.Page  
  12.     {  
  13.        SqlConnection con = newSqlConnection("integrated security=true;Initial Catalog=Iare;Data Source=.");  
  14.        SqlCommand cmd;  
  15.        protected void Page_Load(object sender, EventArgs e)  
  16.         {  
  18.         }  
  20.         protected void Button1_Click(object sender, EventArgs e)  
  21.         {  
  23.             string s = "insert into Student values(@p1,@p2,@p3,@p4)";  
  24.             con.Open();  
  25.             cmd = newSqlCommand(s, con);  
  26.             cmd.CommandType = CommandType.Text;  
  27.             cmd.Parameters.AddWithValue("@p1", TextFName.Text);  
  28.             cmd.Parameters.AddWithValue("@p2", TextLName.Text);  
  29.             cmd.Parameters.AddWithValue("@p3", TextCourse.Text);  
  30.             cmd.Parameters.AddWithValue("@p4", DropDownList1.SelectedItem.Value);  
  31.             cmd.ExecuteNonQuery();  
  32.             con.Close();  
  33.             Lbldsply.Text = "Student Details Has Saved";  
  36.         }  
  37.     }  
  38. }  
Now run the application and check.
Read more articles on ADO.NET: