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:
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.
- SqlConnection con=new SqlConnection(“integratd security=true;initial catalog=Table Name;data source=.”);
DataAdapter: DataAdapter behave as a mediator between data source and table.
- SqlDataAdapter da=new SqlDataAdapter(“Query which has to excute”,Connection object);
DataSet: DataSet contains the tables and relation as in the following figure:
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.
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:
- 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:
- Now insert the data in table by using the following query:
- insertinto Emp values(1,'Sandeep',20000,'Y')
- insertinto Emp values(2,'Mukesh',20000,'Y')
- insertinto Emp values(3,'Rakesh',30000,'N')
- insertinto Emp values(4,'Pappu',35000,'Y')
- insertinto Emp values(5,'Dinesh',25000,'Y')
- insertinto Emp values(6,'Munna',28000,'N')
- insertinto Emp values(7,'Prakash',3200,'Y')
Now run the query: Select * from Emp which will generate output as in the following figure:
- Work on front end.
- Go to Visual Studio.
Create one web application now go to .aspx page and write the following code for design:
- <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="DataList.aspx.cs"Inherits="IARE_Bus.DataList"%>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1"runat="server">
- <div>
- <asp:DataListID="DataList1"runat="server"OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
- <HeaderTemplate>
- StartingPoint EndPoint Via Driver Bus_No
- </HeaderTemplate>
- <ItemTemplate><%#Eval("StartingPoint") % >
- <%#Eval("EndingPoint") %>
- <%#Eval("Via") %>
- <%#Eval("Driver") %>
- <%#Eval("Bus_No") %>
- </ItemTemplate>
- </asp:DataList>
- </div>
- </form>
- </body>
- </html>
The design of web application will be the following:
Now go to aspx.cs and write the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- namespace IARE_Bus
- {
- public partial class DataList : System.Web.UI.Page
- {
- SqlConnection con = newSqlConnection("integrated security=true;initial catalog=Iare;data source=.");
- SqlDataAdapter da;
- protected void Page_Load(object sender, EventArgs e)
- {
- string s = "select * from BusInfo";
- da = newSqlDataAdapter(s, con);
- DataSet ds = newDataSet();
- da.Fill(ds, "Bus");
- DataList1.DataSource = ds.Tables[0];
- DataList1.DataBind();
- }
-
- protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- }
- }
- }
Now run the application and check. In datalist all details of BusInfo table will display.
Read more articles on ADO.NET: