You are on page 1of 77

WORKING WITH EVENTS

 A Web Forms application provides fast, dynamic, and user-


interactive Web Forms pages. When users interact with
different Web controls on a page, events are raised. In the
traditional client forms or client-based Web applications, the
events are raised and handled on the client side.

 Whenever a user interaction requires some kind of processing


on the server, the Web Forms page is submitted to the server,
processed, and then returned to the browser (client). This
sequence is called a round trip.
EVENTS ASSOCIATED WITH ASP.NET
SERVER CONTROLS
 TextBox
 RadioButton and

 CheckBox

 RadioButtonList,

 CheckBoxList,ListBox, andDropDownList

 Button, LinkButton, and ImageButton


EVENT HANDLERS

 When the events are raised, you need to handle them for
processing. The procedures that are executed when an event occurs
are called event handlers
 Event handlers are automatically created when you double-click the
control in Design mode of the form. For example, the following
code is generated when you double-click a Button control whose
ID is RegisterButton. You can then write the code in the event
handler to perform the intended task.

 Public Sub RegisterButton_Click(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles RegisterButton.Click

 End Sub
HANDLING POST BACK
 The Web Forms page is posted back to the server only when a
Button, LinkButton, or ImageButton ASP.NET server control is
clicked. After the page is posted to the server, it is processed
there. You can respond to a button event in one of the
following ways:

 Write an event handler for the Click event of the button.

 Write the event handler for the Load event of the Web Forms
page. The Load event is generated when the form is loaded
from the server to the client (browser).
 To implement this, the Web Forms framework provides the
following options:

 The ViewState: The framework automatically saves the state


of the page and its current properties, and the state of the server
controls and their base properties, with each round trip.

 The State Bags: Every page has a state bag that stores values
to be restored in the next round trip.
 The framework automatically stores and restores page information
with each round trip. So, you do not need to worry about storing
and restoring the page information with each round trip.

 The ViewState contains the state of all the controls on a page


between requests sent to the server.

 The state information is stored as hidden form fields as name-value


pairs in the System.Web.UI.StateBag object.
UNIT 4: USING RICH WEB CONTROLS
4.1- ASP.NET ADROTATOR CONTROL

 The AdRotator is one of the rich web server control of asp.net.


AdRotator control is used to display a sequence of
advertisement images as per given priority of image.

 Adrotator control display the sequence of images, which is


specified in the external XML file. In a xml file we indicate
the images to display with some other attributes, like image
impressions, NavigateUrl, ImageUrl, AlternateText

 In a Adrotator control images will be changed each time while


refreshing the web page.
ADROTATOR CONTROL EXAMPLE IN ASP.NET

 Step 1 – Open the Visual Studio –> Create a new empty Web
application.

 Step 2 – Create a New web page for display AdRotator control.

 step 3 – Drag and drop AdRotator Control on web page from


toolbox.

 step 4 – go to Add New Item –> Add New XML File in project
for write advertisement detail.

 step 5 – Assign XML File to AdvertisementFile Property of


AdRotator control
ADROTATOR CONTROL IN ASP.NET C#
NOW, ADD NEW XML FILE BY GOING TO ADD NEW
ITEM MENU.
SELECT XML FILE, ASSIGN ANY NAME FOR XML FILE AND CLICK ADD BUTTON TO ADD NEW XML FILE.
ADVERTISEMENT XML FILE FOR ADROTATOR CONTROL
 <?xml version="1.0" encoding="utf-8" ?>
 <Advertisements>
 <Ad>
 <ImageUrl>img/1.png</ImageUrl>
 <NavigateUrl>http://SJC.com</NavigateUrl>
 <AlternateText>SJC</AlternateText>
 <Impressions>50</Impressions>
 <Keyword>SJC</Keyword>
 </Ad>

 <Ad>
 <ImageUrl>img/2.png</ImageUrl>
 <NavigateUrl>http://meera.com</NavigateUrl>
 <AlternateText>Meerta Aademy</AlternateText>
 <Impressions>100</Impressions>
 <Keyword>Academy</Keyword>
 </Ad>
 <Ad>
 <ImageUrl>img/3.png</ImageUrl>
 <NavigateUrl>http://meeraacademy.com</NavigateUrl>
 <AlternateText>Meerta Aademy</AlternateText>
 <Impressions>50</Impressions>
 <Keyword>Academy</Keyword>
 </Ad>
 </Advertisements>
NOW, ASSIGN THE XML FILE TO ADROTATOR
CONTROL BY ADVERTISEMENTFILE PROPERTY
OF ADROTATOR CONTROL.
HOW TO USE ADROTATOR CONTROL IN ASP.NET
C#.
CALENDAR CONTROL
 The calendar control is a functionally rich web control, which
provides the following capabilities:

 Displaying one month at a time

 Selecting a day, a week or a month

 Selecting a range of days

 Moving from month to month

 Controlling the display of the days programmatically


 The basic syntax of a calendar control is:

 <asp:Calender ID = "Calendar1" runat = "server">

 </asp:Calender>
PROPERTIES AND EVENTS OF THE CALENDAR
CONTROL

 CaptionAlign
 CellPadding

 CellSpacing

 DayHeaderStyle

 DayNameFormat

 DayStyle

 SelectedDate

 SelectedDates

 SelectedDayStyle

 SelectionMode

 SelectMonthText
 The Calendar control has the following three most important
events that allow the developers to program the calendar
control. They are:

 Events

 SelectionChanged

 DayRender

 VisibleMonthChanged
WORKING WITH THE CALENDAR CONTROL
 Calendar controls allow the users to select a single day, a week,
or an entire month. This is done by using the SelectionMode
property. This property has the following values:

 Properties

 Day

 DayWeek

 DayWeekMonth

 None
 The syntax for selecting days:

 <asp:Calender ID = "Calendar1" runat = "server"


SelectionMode="DayWeekMonth">

 </asp:Calender>
 The following example demonstrates selecting a date and displays the date in a label:
 The content file code is as follows:
 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="calendardemo._Default" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" >

 <head runat="server">
 <title>
 Untitled Page
 </title>
 </head>

 <body>
 <form id="form1" runat="server">

 <div>
 <h3> Your Birthday:</h3>
 <asp:Calendar ID="Calendar1" runat="server SelectionMode="DayWeekMonth" onselectionchanged="Calendar1_SelectionChanged">
 </asp:Calendar>
 </div>

 <p>Todays date is:
 <asp:Label ID="lblday" runat="server"></asp:Label>
 </p>

 <p>Your Birday is:
 <asp:Label ID="lblbday" runat="server"></asp:Label>
 </p>

 </form>
 </body>
 </html>
 The event handler for the event SelectionChanged:
 Protected void Calendar1_SelectionChanged(object
sender, EventArgs e)
{

 lblday.Text =
Calendar1.TodaysDate.ToShortDateString();
 lblbday.Text =
Calendar1.SelectedDate.ToShortDateString();
}
ASP.NET MULTIVIEW CONTROL

 MultiView Control is an asp.net web server control. Multiview


Control is a same as Tab control. If you want make a complex
designing on one web forms then you have to use multiview
control.

 MltiView control is a container of several view control. In a


multiview control there are many view control for designing
separation of view for user.
 The MultiPage control is a container control that contains a set
of PageView elements, which are used to render different
pages in a given screen space. The PageView elements contain
the visible part of the MultiPage control. The MultiPage
control is typically used with the TabStrip control to give users
the ability to navigate from one page to another.

 If we want to display first view on web page, then we need to


write MultiView1.ActiveViewIndex=0.

 Here we take an example to understand how to use multiview


control in asp.net c#.
 The HTML Design code for multiview is :


<body>
 <form id="form1" runat="server">
 <div>

 <table align="center" class="style1" style="border: thin solid #008080">
 <tr>
 <td class="style2"
 style="text-align: center; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #008080;">
 MultiView Control in ASP.Net</td>
 </tr>
 <tr>
 <td style="text-align: center">
 <asp:Button ID="btnview1" runat="server" onclick="btnview1_Click"
 style="font-weight: 700" Text="View1" />

 <asp:Button ID="btnview2" runat="server" onclick="btnview2_Click"


 style="font-weight: 700" Text="View2" />

 <asp:Button ID="btnview3" runat="server" onclick="btnview3_Click"


 style="font-weight: 700" Text="View3" />
 </td>
 </tr>
 <tr>
 <td>
 <asp:MultiView ID="MultiView1" runat="server">
 <asp:View ID="View1" runat="server">
 <table border="1" class="style3">
 <tr>
 <td class="style5" style="text-align: center">
 View -1</td>
 </tr>
 <tr>
 <td class="style4">
 MEERA ACADEMY</td>
 </tr>
 </table>
 </asp:View>
 <asp:View ID="View2" runat="server">
 <table border="1" class="style3">
 <tr>
 <td class="style7" style="text-align: center">
 View -2</td>
 </tr>
 <tr>
 <td class="style6">
 MICRO EDUCATION</td>
 </tr>
 </table>
 </asp:View>
 <asp:View ID="View3" runat="server">
 <table border="1" class="style3">
 <tr>
 <td class="style9" style="text-align: center">
 View -3</td>
 </tr>
 <tr>
 <td class="style8">
 MEERA SOFTWARE</td>
 </tr>
 </table>
 </asp:View>
 </asp:MultiView>
 </td>
 </tr>
 </table>

EXAMPLE OF MULTIVIEW CONTROL IN ASP.NET
NOW, ADD SOME VIEW CONTROL IN
MULTIVIEW CONTROL AS PER YOUR NEEDS
THERE ARE THREE BUTTON ON WEB PAGE FOR
DISPLAY VIEW CONTROL ON PAGE.
TREE VIEW CONTROL

 The TreeView control is used to display hierarchical


representations of items similar to the ways the files and
folders are displayed in the left pane of the Windows Explorer.
Each node may contain one or more child nodes.

 Let's click on a TreeView control from the Toolbox and place it


on the form.
PROPERTIES OF THE TREEVIEW CONTROL

 Property & Description


 BackColor

 Gets or sets the background color for the control.

 BackgroundImage

 Gets or set the background image for the TreeView control.

 BackgroundImageLayout

 Gets or sets the layout of the background image for the


TreeView control.
 BorderStyle

 Gets or sets the border style of the tree view control.


METHODS OF THE TREEVIEW CONTROL
 Method Name & Description
 CollapseAll

 Collapses all the nodes including all child nodes in the tree
view control.
 ExpandAll

 Expands all the nodes.

 GetNodeAt

 Gets the node at the specified location.

 GetNodeCount

 Gets the number of tree nodes.

 Sort

 Sorts all the items in the tree view control.


EVENTS OF THE TREEVIEW CONTROL
 AfterCheck
 Occurs after the tree node check box is checked.

 AfterCollapse

 Occurs after the tree node is collapsed.

 AfterExpand

 Occurs after the tree node is expanded.

 AfterSelect

 Occurs after the tree node is selected.

 BeforeCheck

 Occurs before the tree node check box is checked.


PROPERTIES OF THE TREENODE CLASS
 BackColor
 Gets or sets the background color of the tree node.

 Checked

 Gets or sets a value indicating whether the tree node is in a


checked state.
 ContextMenu

 Gets the shortcut menu that is associated with this tree node.

 ContextMenuStrip

 Gets or sets the shortcut menu associated with this tree node.
EXAMPLE
IN THIS EXAMPLE, LET US CREATE A TREE
VIEW AT RUNTIME
TABSTRIP CONTROL
 The TabStrip control is used to present tabbed controls,
which can be used along with the MultiPage control to
display varied information in a given space.

 The TabStrip control renders tabs that users can click to


switch between the different tabs. The MultiPage control
is used to display multiple pages of data in a given
screen area. This control is typically used with the
TabStrip control.
EXAMPLES
 You use the following syntax to add a TabStrip control to a page:
<tagprefix:TabStrip runat="Server" TabDefaultStyle=".." TabHoverStyle=
".." TabSelectedStyle=".." SepDefaultStyle="..">

 <tagprefix:Tab text=".." >


 <tagprefix:Tab text="Node1.1"/>

 <tagprefix:Tab text="Node1.2">

 </tagprefix:Tab>

 </tagprefix:TabStrip>
PROPERTIES OF THE TABSTRIP
CONTROL

 AutoPostBack

 Defaul

 Orientation Style…etc.,

 The TabStrip control supports the SelectedIndexChanged


event, which is fired when a user shifts from one tab to another.
This event can be trapped to control the formatting and decide
the contents of a particular tab.
USING THE TOOLBAR CONTROL

 The Toolbar control is used to render a toolbar in the client


browsers. At the simplest level, a toolbar is a collection of
graphical buttons. The Toolbar control is typically used to
provide the commonly used functionality to users in a
graphical form.
 To add the Toolbar control to a page, use the following syntax:

 <tagprefix:Toolbar ..>

 <tagprefix:ToolbarButton Text=".." ImageUrl=".." />

 <tagprefix:ToolbarSeparator />

 <tagprefix:ToolbarButton Text=".." ImageUrl=".."/>

 <tagprefix:ToolbarButton Text=".." ImageUrl=".."/>

 </tagprefix:Toolbar>
 The Toolbar control is a container control that contains
elements to define a toolbar. These elements are described as
follows:
 ToolbarButton: Defines a button on the toolbar.

 ToolbarCheckButton: Defines a check button on the toolbar.

 ToolbarCheckGroup: Defines a group of check buttons on the


toolbar.
 ToolbarLabel: Defines a label to display plain text on the
toolbar.
 ToolbarSeparator: Defines a separator on the toolbar, which is
useful in identifying the separate groups of toolbar buttons.
 ToolbarTextBox: Defines a text box on the toolbar
PROPERTIES OF THE TOOLBAR
CONTROL
 AutoPostBack

 DefaultStyle

 SelectedStyle

 Orientation

 EVENTS FOR THE TOOLBAR CONTROL


 ButtonClick
event
 CheckChange event
UNIT 5: ASP.NET DATABASE PROGRAMMING

 ADO.NET provides a bridge between the front end controls


and the back end database. The ADO.NET objects encapsulate
all the data access operations and the controls interact with
these objects to display data, thus hiding the details of
movement of data.

 ADO.NET is upgraded to offer several advantages over


previous versions of ADO and over other data access
components.
 ADO.NET Basics

 NET programming model you might choose — Windows Forms,


Web Forms, or Web Services — ADO.NET will be there to help
you with data access issues. The workings of ADO.NET look at
the key features offered by ADO.NET.

 Presentation tiers- applications

 Internet/interanet- xml based applications

 Business tiers- data sets command

 Data tiers- data stores


Interoperability

The ADO.NET model is designed to take maximum advantage


of the flexibility provided by the large industry acceptance of
XML. ADO.NET uses XML for transmitting datasets among
components and across tiers. Any component that is capable of
reading the XML format can process the data.

Maintainability

After an application is deployed, there might be a need for


changes in the application.
 Programmability

The ADO.NET model uses typed programming to manipulate


objects. In typed programming, the programming environment
or programming language itself recognizes the types of things
that are important to users.
 Performance

ADO.NET is designed to use disconnected data architecture,


which in turn is easier to scale because it reduces the load on
database (does not require any data type conversions). Thus, in
the ADO.NET model, everything is handled at the client side,
which in turn improves performance.
 Scalability

The Web-based, data-centric applications require multiple


users to access data simultaneously. This increases the demand
on data to be accessed, making scalability one of the most
critical. But ADO.NET accommodates scalability by
encouraging programmers to conserve limited resources, and
allows more users to access data simultaneously
ADO.NET OBJECT MODEL
 The ADO.NET Object Model is primarily divided into
two levels:
 Connected Layer: Consists of the classes that comprise
the Managed Providers
 Disconnected Layer: Is rooted in the DataSet

 This section describes both the Managed Providers and


the DataSet.
 Managed Providers

Managed Providers are a collection of classes in the .NET


Framework that provide a foundation for the ADO.NET
programming model.
 The Managed Provider for ADO.NET is the
System.Data.OleDb namespace, which allows you to
access OLE DB data sources. This namespace includes
classes that are used to connect to OLE DB data sources
and execute database queries to access and manipulate
data.
ADO.NET classes for OLE DB data sources
Class Description
OleDbConnection Represents
an open
connection to
a data
source.
OleDbCommand Represents a
SQL query to
be executed
against the
data source.
OleDbDataReader Corresponds
to a forward-
only, read-
only
RecordSet. It
is a highly
optimized
and
nonbuffering
interface for
getting the
results of a
query
executed
against the
data source.
OleDbDataAdapter Represents a
set of data
commands
and a
database
ADO.NET Consumer Objects:
• Data Set DataTable

• DataRow

• DataColumn

• DataRelation

 DataSet Object :

This object represents a set of related tables referenced as one


unit in our application.
 DataTable Object:

This object represents table in DataSet.


 DataRow Object:

This Object represents one row of related data from table.


 DataColumn Object:

This Object represents one column in the table.


 DataRelation Object:

This object represents the relationship between two tables via a


shared column.
 ADO.NET Provider Objects: Connection
 Command

 CommandBuilder DataReader

 DataAdapter

 Connection Object:

 It provides basic connection to our data source. It is the first one.

 Command Object:

This object is used to give a command such as SQL query to a


data source.
 CommandBuilder Object:

It is used to build SQL commands for data modifications.


 DataReader Object :

This is fast, simple to user object that reads a forward-only and


read-only stream of data from a data source.
 DataAdapter Object:

It is used for updating changed data, filling data sets and other
operations.
 The ADO.NET Object Model is primarily divided into two
levels:

 Connected Layer: Consists of the classes that comprise the


Managed Providers

 Disconnected Layer: Is rooted in the DataSet


MANAGED PROVIDERS

 Managed Providers are a collection of classes in the .NET Framework that


provide a foundation for the ADO.NET programming model.

 The Managed Data Providers include classes that can be used for the
following:

 Accessing data from SQL Server 7.0 and later

 Accessing the other OLE DB providers

 The Managed Provider for ADO.NET is the System.Data.OleDb


namespace, which allows you to access OLE DB data sources. This
namespace includes classes that are used to connect to OLE DB data
sources and execute database queries to access and manipulate data.
ADO.NET CLASSES FOR OLE DB DATA SOURCES

 OleDbConnection

 OleDbCommand

 OleDbDataReader

 OleDbDataAdapter

 OleDbParameter

 OleDbError
ADO.NET CLASSES FOR SQL SERVER

 SqlConnection
 SqlDataAdapter
 SqlCommand
 SqlParameter
 SqlError

 To demonstrate how to open a connection to a SQL Server database and


fill the DataSet (discussed later in this section) with a database query
result, consider the following code:

 Dim connection As New

 SqlConnection("server=localserver;uid=sa;pwd=;database=Sales")
 Dim command As New SqlDataAdapter("SELECT * FROM Products
Where ProductID=@ID", connection)
 connection is a SqlConnection class object that
represents a connection to the SQL Server database.

 command is a SqlDataAdapter class object that


represents a set of data commands and a database
connection.

 param1 is a SqlParameter class object that represents


the parameter to be passed in the T-SQL command.

 dataset is a DataSet class object that represents the


DataSet that is filled by the query results.
DATASET CLASS

 A DataSet contains a collection of DataTables (the Tables


collection). A DataTable represents one table of in-memory
data.

 The DataSet comprises the Disconnected Layer of ADO.NET.


The DataSet consists of a local buffer of tables and relations.
 DataAdapter will acts as a Bridge between DataSet and
database. This data adapter object is used to read the data
from database and bind that data to dataset. Dataadapter is a
disconnected oriented architecture.

 DataSet is a disconnected orient architecture that means there


is no need of active connections during work with datasets
and it is a collection of DataTables and relations between
tables. It is used to hold multiple tables with data. You can
select data form tables, create views based on table and ask
child rows over relations. Also DataSet provides you with rich
features like saving data as XML and loading XML data.
 DataReader is used to read the data from the database and it
is a read and forward only connection oriented architecture
during fetch the data from database. DataReader will fetch the
data very fast when compared with dataset. Generally, we will
use ExecuteReader object to bind data to datareader.

 DataTable represents a single table in the database. It has


rows and columns. There is no much difference between
dataset and datatable, dataset is simply the collection of data
tables.
 Data Reader
 protected void BindGridview()

{

 using(SqlConnection conn = new SqlConnection("Data


Source=abc;Integrated Security=true;Initial
Catalog=Test"))
{

 con.Open();

 SqlCommand cmd = new SqlCommand("Select


UserName, First Name,LastName,Location FROM
Users", conn);
 SqlDataReader sdr = cmd.ExecuteReader();
gvUserInfo.DataSource = sdr; gvUserInfo.DataBind();
 conn.Close(); } }
 DataSet
 protected void BindGridview()

{

 SqlConnection conn = new SqlConnection("Data


Source=abc;Integrated Security=true;Initial
Catalog=Test");
 conn.Open();

 SqlCommand cmd = new SqlCommand("Select


UserName, First Name,LastName,Location FROM
Users", conn);
 SqlDataAdapter sda = new SqlDataAdapter(cmd);

 DataSet ds = new DataSet(); sda.Fill(ds);


gvUserInfo.DataSource = ds; gvUserInfo.DataBind();
 }
 DataAdapter
 protected void BindGridview()

{

 SqlConnection con = new SqlConnection("Data


Source=abc;Integrated Security=true;Initial
Catalog=Test");
 conn.Open(); SqlCommand cmd = new
SqlCommand("Select UserName, First
Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();

 sda.Fill(ds);

 gvUserInfo.DataSource = ds; gvUserInfo.DataBind();

 }
Data Table
 protected void BindGridview()

{

 SqlConnection con = new SqlConnection("Data


Source=abc;Integrated Security=true;Initial Catalog=Test");
 conn.Open();

 SqlCommand cmd = new SqlCommand("Select UserName,


First Name,LastName,Location FROM Users", conn);
 SqlDataAdapter sda = new SqlDataAdapter(cmd);

 DataTable dt = new DataTable();

 sda.Fill(dt);

 gridview1.DataSource = dt; gvidview1.DataBind();

 }
 ExecuteNonQuery
 ExecuteNonQuery method is used to execute SQL
Command or the storeprocedure performs, INSERT,
UPDATE or Delete operations. It doesn't return any data
from the database. Instead, it returns an integer
specifying the number of rows inserted, updated or
deleted.
 ExecuteReader:

 ExecuteReader method is used to execute a SQL


Command or storedprocedure returns a set of rows from
the database.
 Executescalar

 ExecuteScalar method is used to execute SQL


Commands or storeprocedure, after executing return a
single value from the database. It also returns the first
column of the first row in the result set from a database.
 Scalar
 public class Sample
 {
 public string Test(int Id)
 {
 SqlConnection sqlCon = null;
 String SqlconString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].Connecti
onString;
 using (sqlCon = new SqlConnection(SqlconString))
 {
 sqlCon.Open();
 SqlCommand Cmnd = new SqlCommand("SELECT NAME FROM TABLE_NAME WHERE ID
=@ID", sqlCon);
 Cmnd.Parameters.AddWithValue("@ID", Id);
 object result = Cmnd.ExecuteScalar();
 if (result != null)
 {
 string name = result.ToString();
 }
 sqlCon.Close();
 }
 return "";
 }

 }
 Reader
 public class Sample
 {
 public string Test(int Id)
 {
 SqlConnection sqlCon = null;
 String SqlconString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionS
tring;
 using (sqlCon = new SqlConnection(SqlconString))
 {
 sqlCon.Open();
 SqlCommand Cmnd = new SqlCommand("SELECT *FROM TABLE_NAME WHERE ID=@ID", sql
Con);
 Cmnd.Parameters.AddWithValue("@ID", Id);
 SqlDataReader rdr = Cmnd.ExecuteReader();
 while (rdr.Read())
 {
 string name = rdr["Name"].ToString();
 string age = rdr["Age"].ToString();
 string city = rdr["City"].ToString();
 }
 sqlCon.Close();
 }
 return "";
 }

 }
 Nonquery
 public class Sample
 {
 public void Test(int Id, string Name)
 {
 SqlConnection sqlCon = null;
 String SqlconString = ConfigurationManager.ConnectionStrings["SqlConnec
tionString"].ConnectionString;
 using (sqlCon = new SqlConnection(SqlconString))
 {
 sqlCon.Open();
 SqlCommand Cmnd = new SqlCommand("PROC_NAME", sqlCon);
 Cmnd.CommandType = CommandType.StoredProcedure;
 Cmnd.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = Id;
 Cmnd.Parameters.AddWithValue("@NAME", SqlDbType.NVarChar).Value
= Name;
 int result= Cmnd.ExecuteNonQuery();
 sqlCon.Close();
 }
 }
A DATATABLE CONSISTS OF THE FOLLOWING
THE DATA ACCESS CLASSES OF ADO.NET

 DataSet
Represents a complete collection of tables, relationships, and
constraints.

 Data Adapter
Represents a database query or stored procedure that is used to
populate the DataSet object.

 DataTable
Represents a data source that stores data in row and column format.

 DataColumn, data Row:


Represents a column in a DataTable and Data Row.
COMMUNICATING WITH OLEDB DATA SOURCES USING ADO.NET

 System.Data.OleDb.OleDbCommand class
 This class encapsulates the commands that need to be sent to the
OLE DB data source. Applications use the OleDbCommand class to
create select, insert, update, and delete commands.

 System.Data.OleDb.OleDbDataReader class
 This class is very useful to all applications that want to retrieve data
returned from a query to the database and want to process one record
at a time.

System.Data.OleDb.OleDbDataAdapter class
 The data adapter acts as the conduit between the client

application and the database connection, command objects


THANK YOU

You might also like