C# -ADO.NET
C# -ADO.NET
C# -ADO.NET
NET, creating a
connection to a database, OLEDB database,using OLEDB adapter
for excel file, ODBC data source, ADO.NET commands, data
adapters, creating data view, data reader, stored procedures.
-
- Disconnected architecture has certain advantages (uses less no. of
resources, easy to migrate to Internet).
- Provides a set of components to create distributed applns.
- it is an imp & integral part of a .net framework – provides
consistent access to data source (MS SQL server, OLEDB, oracle &
XML).
- used to retrieve, manipulate & update data present in these data
sources.
- Includes data providers for connecting to a DB, executing
commands & retrieving requests.
- ADO .net classes are found in system. Data. Dll & as integrated
with XML classes found in system. Xml. Dll.
- ADO – Activex Data Objects
- It is a Data access component.
- ADO. Net – latest improvement after ADO –
- provide platform interoperability & scalable data access.
- In .Net framework, data is transmitted in xml format, ∴ any appln
that can read xml format can process data.
- Provides access to diverse data sources by using a consistent &
standardized programming model.
- Is upgraded to offer several advances over ADO &other data
access components.
- Bring together all the classes that allow data handling.
(ADO model uses the concept of record sets-fail at internet
interoperability)
- ADO .net expands the boundaries of interoperal to the internet.
Instead of record sets, ADO uses Dataset &Data Reader objects to
access manipulate data.
▪ Key features of ADO .net:
1. Inter operability: ADO .net model is designed to take most
advantage of flexibility provided by the large acceptance of xml.
- ADO .net uses xml for transmitting datasets among components
&across tries.
- Any component that is capable of reading xml format can process
the data.
2. Maintainability: After an application is deployed, there might be a
need for changes in the application.
- As the performance load on a deployed application server grows,
system resources can become inadequate, resulting in higher
response timer.
- As a solution to this problem, the application might need to
undergo architectural changes by adding tiers.
- This transformation becomes easier if the original application is
implemented in ADO .net using data sets.
- In ADO.net, the communication b/w tiers is relatively easy,
because the tiers can transmit data through xml.
- It is formatted data sets.
3. Programmability: ADO .net model uses typed programming to
manipulate objects.
- In typed programming, the programming
environment/programming language itself recognizes the types of
things that imp to users.
- In typed data sets, errors in the syntax caused by misspellings are
detected at compile time (non – typed – run time).
4. Performance: In ADO, while transmitting data across tiers using
COM marshalling in the form of disconnected record sets, the
values must be converted to data types that are recognized by
COM, resulting in poor performance ADO .net is designed to use
disconnected data architecture.
- Which is easier to scale, because it reduces the load on data
base(no need of data conversions).
- Thus, in ADO .net, everything is handled, at client side, which in
turn improves performance.
5. Scalability: web-based, data centric applications require multiple
users to access data simultaneously.
- This increases the demand on data to be accessed.
- Application that use resource, (DB connections, DB locks) cannot
support more users to access data simultaneously.
- Because ADO .net uses disconnected data access, application don’t
retain DB locks or active DB connects for longer durations.
- Hence, ADO .net accommodates scalability by encouraging
programmers to conserve limited resources & allows more users to
access data simultaneously.
▪ Components of Dataset:
1. Data Table: consists of Data Roe & Data Column & stores data in
the table row format.
- The Data table is the central objects of ADO .net library.
- Data table objects are case-sensitive.
- New Row( ) method is used to add row to a table.
- The maximum number of rows that a Data Table can contain is
16,777,216.
2. Data View: Represents, a customized view of Data Table for
sorting, filtering, searching, editing & navigation.
- can be used to present a sunset of data from data table
- create a view based on a present condition specified in Row State
Filter property.
3. Data Column: consists of number if columns that comprises a Data
Table.
- essential building blocks of Data Table – Data Type property
determines the kind of Data that a column holds.
4. Data Row: represents a row in the Data Table u can use data row
objects & its properties & methods to retrieve, evaluate, insert,
delete & update the values in the Data Tab use New Row( )
method of data table to create a new Data Row( ) & Add( )
method to add the Data Row. Delete Data Row by calling Remove(
) method.
5. Data Relation: allows u to specify relations b/w various tables –
used to related two Data Table objects to each other through Data
Column objects retrieving large amounts of data. Call close( )
method every time u finish using Data Reader obj.
- Both Data Reader & Data Set are used to retrieve data but the
functionality is diff use Dataset when u want to manipulate your
data, access your data dynamically use Data Reader for returning
data in forward only & Read only manner.
❖ Creating a connection to a DB
❖ Command object:
- Data view is used to get a snapshot of data in a table & with it. It
is same as a read-only mini-Datasets
- load only subset of a Data Set into Data view.
- Data view provides dynamic view of data. It provides a Data Row
array from a table based on a particular filter or sort order.
- U can apply diff sorting & filtering criteria with the help of Data
view.
- // [add 2 buttons & 1 data Grid View]
1- button – sort 2- button – only in Indian
- Using System.Data.SQLclient;
- Private void From1 _load (OS, EA, e) {
DataGridView1.DataSource= GetTable.Default view
}
Public DataTable GetTable( )
{
String connection string= “Data source= KGCW; Initial catlog=
North wind; Integrated sec= True”;
Data Table customer= new Data Table(“customer”);
Using (SQL connection con= new SQL connection (connection
string))
{
Sql command cmd= con . create command( );
cmd.command Text= “select * from [customer]”;
con.Open( );
customer. Load (cmd. ExecuteReader
(commandbehaviour.Close connection));
}
Return customer;
}
private void button1_click (OS, EA, e) {
Data view dv= new Data View(Get Table( ));
dv.sort= “city ACS”;
DataGirdView1.Data source= dv;
}
Private void button2_click (OS, EA, e) {
DataView dv= new Data view (GetTable( ) );
dv.row Filter= “country= ‘India’”;
DataGridView1.DataSource= dv;
}
❖ Using Data Reader to work with DBs:
Using System.Data.SQLclient;
Private void button_click(OS, EA, e) {
SQLData Reader rds= null;
SQLconnection con= null;
SQLcommand cmd= null;
Try {
String connection string= “Data source = KGCW;
Initial catalog= northwind; Integrated security True;
Con= new sql connection (connection string);
Con.Open( );
String command Text= “select Fnm, Lnm” + “From Std” +
“where (Lnm Like @ FIND)
Cmd= new sql command(command Text);
cmd. connection= con;
cmd. parameters. Add(new sql parameter(“@fing”, System.
Data. Sql Db Type. NVar Char, 2 “Lnm”));
cmd. parameter[“@find”]. Value= text box1. Text;
rdr= cmd. Execute Reader( );
list Box1. Items. Clear( );
while (rdr. Read( ))
{
List Box1. Items. Add (rdr[“Fnm”]. To string( )+ “ ”+rdr
[“Lnm”]. To string( ));
}
}catch (Execution ex)
{ Message Box. Show(ex. Message); }
Finally {
If (rdr!= null)
Rdr. Close( );
If (con. State= connection state. Open)
Con. Close( );
} }
❖ Stored procedure:
- Stored procedure is a pre compiled set of SQL commands that are
stored on a DB.
- It is compiled once & used repeatedly by client appln.
- Creating a stored procedure in SQL server 2008:
Create procedure Get product Details
@ product ID int
As
Select product ID, product Name, Quantity, Unit Price From
product WHERE product ID= @ product Id.
// a stored procedure is created with one parameter of Integer
type.
Stored procedure is executed by Execute Get Product Details 3
(product ID=3)
- Create stored procedure as a CLR object in .Net framework. for
this, add a stored procedure CLR object in SQL server proj.
Steps to create product Details SP proj & Get Product Details
stored procedure in VS 2012.
1)Open Visual studio 2012.
2)Create a SQL server DB project, named Product Details SP.
3)Click OK (product Details SP proj is displayed)
4)Right click the Product Details SP in solution Explorer & select
Add→ stored procedure option.
5)Select Installed→ SQL server→ SQL CLR C# from the left pane &
then SQL CLR C # stored procedure template in middle pane.
6)Enter Get Product Details SP.cs in Name text box & enter an
appropriate proj loc in Location combo box.
7)Click Add button (stored procedure is added to proj).
8)Modify the code of Get Product Details SP.cs file.
Using System;
Using System.Data;
Using System.Data.Sql Client;
Using System.Data.Sql Types;
Using Microsoft.sqlserver.Server;
Public partial class stored procedures {
[Microsoft.sqlserver.Server.Sql Procedure]
Public static void Get Product Details SP(int prod ID) {
Sql connection con= new sql connection(“context connection=
true”)
Con.Open( );
Sql command cmd=new sql command(“SELECT Product ID,
Product nm, Qty, Units price, Units FROM products WHERE product
ID=@ prod ID order By product nm”, con);
cmd. parameters. Add(“@ prod ID, Sql Db Type. Int);
cmd. parameters[“@prod ID”]. Value= Product ID;
sqlData Reader sdr= cmd. Execute Reader( );
sqlPipe SP= Sql context. Pipe;
SP. Send(sdr);
Con. Close( );
} }
- A Sql connection object is created with the context connection=
true string.
- The Sql command object is created by passing the connection
object. An objects of Sql Data Reader class is returned by Execute
Reader( ) method, which is returned to client by using Send( )
method of Sql Pipe class.
- 1st compile this code into a DLL file. Then load it into SQL server &
create T-SQL stored procedure press F5 to run proj.
9)Now, open SQL server 2008, & create query to create an assembly
& stores procedure.
Create assemble Product Details Assemble from ‘D:\ Net\product
Details SP. Dll’ with permission-set= safe
Go
Create procedure Product Details Procedure
(@ Prod ID int)
As external name Product Details Assembly. Stored procedure Get
Product Details SP
Go
Execute SP-configure ‘clr enabled’, 1
Reconfigure
Go
Execute Product Details Procedure 3
(display prod Details of prod ID 3)
- 3 types of stored procedures.
1. Return records –stored procedure:
Are used to find specific records, sort & filter those records &
then return the response of find, sort & filter options to a Data Set
object or list-bound control. These procedure are based on SQL
select stmts.
2. Return value stored procedure, also known as scalar stored proc:
(call Execute Scalar method of command object)
Used to execute a DB command or F4 that returns a single
value – return only a value.
3. Action stored procedures: (use Execute Non Query method of
command object)
Are used to perform some function in the DB but not return a
record\value. These functions may include updating, editing or
modifying the data.
INTRODUCTION TO ASP.NET:
Overview:
- Asp.net is one of the most powerful web application development
platforms.
- It is becoming more useful & popular with the release of upgraded
versions.
- Asp.net 4.5 includes several enhancements in ASP.NET core, run
time & framework and ASP.NET web forms & contain a new version
of MVC(Model, View, Controller) named ASP.NET MVC4.
- The new Javascript, HTML & CSS editors are also integrated with
visual studio 2012 to simplify the web appln development.
- Asp.net provides services to allow the creation, development &
execution of web appln & web services.
- Asp.net is a server side technology.
- Web aplns are built using web forms, Asp.net comes with built-in
web forms controls, which are responsible for generating the user
- Web forms are designed to make building web-based applications
easy.
● Intrinsic controls:
- Are HTML elements that gather user info. They are specified in ASP
namespace. They can create intelligent controls that automatically
maintain standard & provide extra features.
<asp: Button> <asp: Label> <asp: Image> <asp: Hyper
Link>
<asp: Text Box> <asp: Table> <asp: Radio Button> <asp:
List Box> <asp: Table Row>
● Diff categories of web server controls:
1. Standard controls(Intrinsic – link HTML)
Ex: Label, Text box, Check box.......
2. Data controls
Ex: grid view, data list, repeater....
3. Navigation controls
Ex: tree view, menu.....
- Syntax:
<asp: control name id= “ ” runat= “server”...>
</asp: control name>
● Web form is providing 3 views
1. Design view: this will display preview of web page output &
supports arrangement of controls using drag & drop.
2. Source view” this will display markup content (tags) of web page –
allows creating controls manually.
3. Logic view” allows developer to write logic part of web page.
❖ Application structure & state:
❖ Using states:
- by using in a web appln, u can preserve the state of appln either at server/
client end. The string of web appln helps u to store runtime changes that have
been made to web appln.
❖ Validation controls
- Are the controls used for validating the data entered in an input
control ∍ Text Box.
- When a user enters data on a web page & submits the page to the
server, validation controls are invoked to check the data entered by
user.
- If any of the data is invalid the validation control displays an error
message on the screen.
- The error message is defined as a property value of validation
control.
- Ensuring proper input from user is called validation.
- Ex: user name cannot be blank
Mobile number requests 10 digit nos.
- Validation controls can be used to validate user input at client side/
server side, default is client side validation controls will provide
built- in code to perform diff types of validations, this makes
developer job easier & faster in web site development – save time
& enhances efficiency.
- (from asp.net 3.0 onwards validation controls script is not visible to
developer)
● Validation controls
1. Required Field Validator control.
2. Range Validator control.
3. Compare Validator control.
4. Regular Expression Validator control.
5. Custom validator control.
6. Validation summary control.
● Comman properties of validation controls:
1. Control to Validate: specify std control id to validate user inpute.
2. Text: specify error message to be displayed if user provides an
invalid input.
3. Error message: specify error message to be displayed with
validation summary control.
4. Enable client script – true/ false
True [default] – client side validation
False - server side validation
● Base Validator class:
System. Web. UI. Web controls. Base Validator class provides basic
impl required for all validation controls.
NOTE:
2. One validation control can validate only one text box, it can not
validate more than one text box.
3. Text box applied with more than one validation control requires
setting display property.
❖ Master pages:
- Earlier, each page of a web site had a diff style applied to it, which
made if diff for developers to provide a consistent look throughout
web site.
- A master page is used to incorporate visual inheritance in a web
site/web appln & define a common layout for its web pages.
(master page is used to create a sample layout, which in turn is
derived by all pages of website.
- Master page provides a feature of (standardized user interface)
which is common to all pages.
- ∴all pages in a website inherit the master age to maintain the
consistency in website.
- A theme is a collection of property settings that define the same
appearance of controls & web pages across entire website.
● Need of master pages & Themes:
- Master page defines a standardized layout for website. Master
page contains mark-ups & controls that can be shared across diff
web pages.
- The functionality of master pages improves the maintainability of
ASP.net website & avoids duplication of code.
- In website, if u want to include a header, footer, banners &
navigation menus.
- If master page is not used, then layout & control elements must
be define for every page, u have to copy & paste same code in
every page which is tedious & time-consuming process.
- It also affect the appearance of web pages.
- If u want to modify the header or footer of website, u need to
make modifications in each page manually.
- ∴to maintain consistency & manageability, use master page.
- Similarly theme a can be used with master pages to define the
style of a website globally & impl same style across the website.
● Understanding Master pages:
- Master pages enable the template based development of a
website. ASP.net master page defines the overall layout of website
& all web pages are derived from this master page.
- It can contain mark-ups, controls, banner, navigation menus &
other elements.
- It is an ASP.net file having .master as its extension. A master page
includes std & HTML control.
- Master page is define by specifying @ Master directive at the top
of web page.
<%@ Master language= “C#” code file= “master page.master.cs”
Inherits= “Master page”>
- This directive states that it belong to a master page file its
properties ∍ banner, header, footer & menus.
- By default, a master page contains a single Content Place Holder
control, which adds the dynamic content to a web page, u can add
multiple Content Place Holder controls in a master page.
<asp: Content Place Holder id= “head” runat= “server”>
- The diff b/w a simple web page & master page in terms of code is
that the master page contains an empty Content Place Holder
control.
- The syntax to refer a master page is, <%@ page language= “C#”
Master Page File= “Master page master” Title= “content page”%>
- Master Page File attribute of the @ page directive helps in binding
a master page file with the content page of website.
❖ WEB SERVICES
- Web service is an independent& self-sustained unit of software
application hosted on the Internet.
- A webservice is an entity that you can program to particular entity
that you can program to provide a particular functionality to
applications over internet.
- You can use a web service to calculate simple interest, compound
interest, calculate tax, pay slip etc
- A we service allows a websites to communicate with other
websites.
- Irrespective of programming language in which they are created.
- A web service can be accessed by any application, regardless of
software& hardware platforms on which application is running.
- Web services use standards ∍ SOAP& WSDL(SOAP- simple object
access protocol)(WSDL- web service description language)
- A web services does not have any user interface, it only contains
logic for providing specific services to its consumers
- A web services providers an abstraction between the consumer&
the provider of web service
Advantages of web services over COM& DCOM
1. web services are simple to use& implied on varied platforms.
2. web services are loosely coupled, so their interfaces & method
can be extended.
3. web services do not carry any start info with them, so that
multiple requires can be processed simultaneously.
- Web services are most appropriate while communicating across
platforms or enforcing trusted connections b\w server & client.
Element Description
name
❖ Architecture of ADO.NET:
ADO.NET architecture.
- The data provider contains the connection, command, data reader
& Data Adapter objects.
- The connection object provides connectivity to the data source.
The command object allows the access to DB commands, such as
return data, modify data &send data.
- The Data Reader object provides a high-performance stream of
data from a data source.
- The Data Adapter object uses the command object to execute SQl
commands. The Data Adapter object loads the dataset with data.
▪ Data providers in ADO.NET
- A data provider is a set of related components that work together
to provide data in an efficient manner.
- It is used in ADO.NET for connecting to a DB, executing
commands & retrieving results. The data providers increase
performance without compromising on functionality.
▪ Objects of Data provider:
- The Data provider in ADO .net consists for objects.
1. Connection – creates connection to the data source (DB connection
– base class for all connection objects).
- The connection object has methods for opening & closing
connection & beginning a transaction.
- The .net frame work provides for types of connection classes.
a. SQL connection object – designed specifically to connect to MS
SQL server.
b. Ole DB connection – designed to provide connections to a wide
range
c. ODBC connection – provides access to data sources using odbc.
d. Oracle connection – provides access to oracle.
2. Command – executes a command against the data source &
retrieve a Data Reader or Dataset.
- It executes INSERT, UPDATE or DELETE command against data
source. (base class is DB command class).
- Reps 4 classes.
1. SQL command 2. Ole DB command 3. Oracle command 4. ODBC
command.
- Provides 3 methods to execute commands on DB.
I. Execute Non Query ( ) – executes the commands section INSERT,
UPDATE or DELETE that have no return value.
II. Execute Scalar ( ) – return a single value from DB query.
III. Execute Reader ( ) – return a result set (Data Reader object).
3. Data Reader: provides a forward-only & Read-only connected
Result-set.
- The base class for all data reader objects DB Data Reader class.
- The Data Reader object is represented by 4 Data Reader classes.
- Sql Data Reader, Oracle Data Reader, Ole Db Data Reader & Odbc
Data Reader. (Data Reader cannot be directly instantiated).
4. Data Adapter: updates the Data from the data source base
- Acts as an intermediary for all communication b/w the database &
dataset
- It is used to fill a Data Table or Data set with data from the data
base using Fill ( ) method.
- commits the changes to the DB by calling update ( ) method.
- Provides the 4 properties that represent the DB command, select
command, insert command, delete command & update command.
▪ Components of Dataset:
1. Data Table: consists of Data Roe & Data Column & stores data in
the table row format.
- The Data table is the central objects of ADO .net library.
- Data table objects are case-sensitive.
- New Row( ) method is used to add row to a table.
- The maximum number of rows that a Data Table can contain is
16,777,216.
2. Data View: Represents, a customized view of Data Table for
sorting, filtering, searching, editing & navigation.
- can be used to present a sunset of data from data table
- create a view based on a present condition specified in Row State
Filter property.
3. Data Column: consists of number if columns that comprises a Data
Table.
- essential building blocks of Data Table – Data Type property
determines the kind of Data that a column holds.
4. Data Row: represents a row in the Data Table u can use data row
objects & its properties & methods to retrieve, evaluate, insert,
delete & update the values in the Data Tab use New Row( )
method of data table to create a new Data Row( ) & Add( )
method to add the Data Row. Delete Data Row by calling Remove(
) method.
5. Data Relation: allows u to specify relations b/w various tables –
used to related two Data Table objects to each other through Data
Column objects retrieving large amounts of data. Call close( )
method every time u finish using Data Reader obj.
- Both Data Reader & Data Set are used to retrieve data but the
functionality is diff use Dataset when u want to manipulate your
data, access your data dynamically use Data Reader for returning
data in forward only & Read only manner.
❖ Creating a connection to a DB
❖ Command object:
- Data view is used to get a snapshot of data in a table & with it. It
is same as a read-only mini-Datasets
- load only subset of a Data Set into Data view.
- Data view provides dynamic view of data. It provides a Data Row
array from a table based on a particular filter or sort order.
- U can apply diff sorting & filtering criteria with the help of Data
view.
- // [add 2 buttons & 1 data Grid View]
1- button – sort 2- button – only in Indian
- Using System.Data.SQLclient;
- Private void From1 _load (OS, EA, e) {
DataGridView1.DataSource= GetTable.Default view
}
Public DataTable GetTable( )
{
String connection string= “Data source= KGCW; Initial catlog=
North wind; Integrated sec= True”;
Data Table customer= new Data Table(“customer”);
Using (SQL connection con= new SQL connection (connection
string))
{
Sql command cmd= con . create command( );
cmd.command Text= “select * from [customer]”;
con.Open( );
customer. Load (cmd. ExecuteReader
(commandbehaviour.Close connection));
}
Return customer;
}
private void button1_click (OS, EA, e) {
Data view dv= new Data View(Get Table( ));
dv.sort= “city ACS”;
DataGirdView1.Data source= dv;
}
Private void button2_click (OS, EA, e) {
DataView dv= new Data view (GetTable( ) );
dv.row Filter= “country= ‘India’”;
DataGridView1.DataSource= dv;
}
Using System.Data.SQLclient;
Private void button_click(OS, EA, e) {
SQLData Reader rds= null;
SQLconnection con= null;
SQLcommand cmd= null;
Try {
String connection string= “Data source = KGCW;
Initial catalog= northwind; Integrated security True;
Con= new sql connection (connection string);
Con.Open( );
String command Text= “select Fnm, Lnm” + “From Std” +
“where (Lnm Like @ FIND)
Cmd= new sql command(command Text);
cmd. connection= con;
cmd. parameters. Add(new sql parameter(“@fing”, System.
Data. Sql Db Type. NVar Char, 2 “Lnm”));
cmd. parameter[“@find”]. Value= text box1. Text;
rdr= cmd. Execute Reader( );
list Box1. Items. Clear( );
while (rdr. Read( ))
{
List Box1. Items. Add (rdr[“Fnm”]. To string( )+ “ ”+rdr
[“Lnm”]. To string( ));
}
}catch (Execution ex)
{ Message Box. Show(ex. Message); }
Finally {
If (rdr!= null)
Rdr. Close( );
If (con. State= connection state. Open)
Con. Close( );
} }
❖ Stored procedure:
- Stored procedure is a pre compiled set of SQL commands that are
stored on a DB.
- It is compiled once & used repeatedly by client appln.
- Creating a stored procedure in SQL server 2008:
Create procedure Get product Details
@ product ID int
As
Select product ID, product Name, Quantity, Unit Price From
product WHERE product ID= @ product Id.
// a stored procedure is created with one parameter of Integer
type.
Stored procedure is executed by Execute Get Product Details 3
(product ID=3)
- Create stored procedure as a CLR object in .Net framework. for
this, add a stored procedure CLR object in SQL server proj.
Steps to create product Details SP proj & Get Product Details
stored procedure in VS 2012.
1)Open Visual studio 2012.
2)Create a SQL server DB project, named Product Details SP.
3)Click OK (product Details SP proj is displayed)
4)Right click the Product Details SP in solution Explorer & select
Add→ stored procedure option.
5)Select Installed→ SQL server→ SQL CLR C# from the left pane &
then SQL CLR C # stored procedure template in middle pane.
6)Enter Get Product Details SP.cs in Name text box & enter an
appropriate proj loc in Location combo box.
7)Click Add button (stored procedure is added to proj).
8)Modify the code of Get Product Details SP.cs file.
Using System;
Using System.Data;
Using System.Data.Sql Client;
Using System.Data.Sql Types;
Using Microsoft.sqlserver.Server;
Public partial class stored procedures {
[Microsoft.sqlserver.Server.Sql Procedure]
Public static void Get Product Details SP(int prod ID) {
Sql connection con= new sql connection(“context connection=
true”)
Con.Open( );
Sql command cmd=new sql command(“SELECT Product ID,
Product nm, Qty, Units price, Units FROM products WHERE product
ID=@ prod ID order By product nm”, con);
cmd. parameters. Add(“@ prod ID, Sql Db Type. Int);
cmd. parameters[“@prod ID”]. Value= Product ID;
sqlData Reader sdr= cmd. Execute Reader( );
sqlPipe SP= Sql context. Pipe;
SP. Send(sdr);
Con. Close( );
} }
- A Sql connection object is created with the context connection=
true string.
- The Sql command object is created by passing the connection
object. An objects of Sql Data Reader class is returned by Execute
Reader( ) method, which is returned to client by using Send( )
method of Sql Pipe class.
- 1st compile this code into a DLL file. Then load it into SQL server &
create T-SQL stored procedure press F5 to run proj.
9)Now, open SQL server 2008, & create query to create an assembly
& stores procedure.
Create assemble Product Details Assemble from ‘D:\ Net\product
Details SP. Dll’ with permission-set= safe
Go
Create procedure Product Details Procedure
(@ Prod ID int)
As external name Product Details Assembly. Stored procedure Get
Product Details SP
Go
Execute SP-configure ‘clr enabled’, 1
Reconfigure
Go
Execute Product Details Procedure 3
(display prod Details of prod ID 3)
- 3 types of stored procedures.
1. Return records –stored procedure:
Are used to find specific records, sort & filter those records &
then return the response of find, sort & filter options to a Data Set
object or list-bound control. These procedure are based on SQL
select stmts.
2. Return value stored procedure, also known as scalar stored proc:
(call Execute Scalar method of command object)
Used to execute a DB command or F4 that returns a single
value – return only a value.
3. Action stored procedures: (use Execute Non Query method of
command object)
Are used to perform some function in the DB but not return a
record\value. These functions may include updating, editing or
modifying the data.