Click here to Skip to main content
15,881,872 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
guys i m new in asp.net..pls tell me what is stored procedure in aspnet. and why we use in asp.net. by example?and how to call it
Posted
Comments
Krunal Rohit 27-Nov-15 3:34am    
Not a question.
you can find lots of suggestion about this? Did you google your issue ?

-KR
deepankarbhatnagar 27-Nov-15 4:38am    
Try search on google. We are not here for spoon feeding.

A Stored Procedure is a set of SQL statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of stored procedures can be helpful in controlling access to data (end-users may enter or change data but do not write procedures), preserving data integrity (information is entered in a consistent manner), and improving productivity (statements in a stored procedure only need to be written one time).
Advantage of stored procedure

a) Stored procedure allows modular programming.You can create the procedure once, store it in the database, and call it any number of times in your program.

b) Stored Procedure allows faster execution. If the operation requires a large amount of SQL code is performed repetitively, stored procedures can be faster. They are parsed and optimized when they are first executed, and a compiled version of the stored procedure remains in memory cache for later use. This means the stored procedure does not need to be reparsed and reoptimized with each use resulting in much faster execution times.

c) Stored Procedure can reduce network traffic.An operation requiring hundreds of lines of Transact-SQL code can be performed through a single statement that executes the code in a procedure, rather than by sending hundreds of lines of code over the network.

d) Stored procedures provide better security to your data. Users can be granted permission to execute a stored procedure even if they do not have permission to execute the procedure's statements directly.

In SQL we are having different types of stored procedures are there

a) System Stored Procedures
b) User Defined Stored procedures
c) Extended Stored Procedures

Calling stored procedure in asp.net

C#
SqlConnection con = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
con.Open();
dr= cmd.ExecuteReader();
whiledr.Read()
{
// Data is accessible through the DataReader object here.
}
con.Close();
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900