The stored procedure is like a function and sub-process in its actual programming language, contains certain content, stored in a database in a database, convenient for users to call at any time.
There are many benefits to using stored procedures to perform database operations:
1. Save in the database in the form of compilation, so the speed of execution is fast
2. Allow modular programming to make it easy to modify
3. Save network bandwidth
4. Improve security
This is established a simplest stored procedure, and the database is Northwind
Create Procedure My.StoredProcedure AS
Select Firstname, Lastname
From
Employees
Return
After saving, you can find a memory process in the database in the database.
Create a new web form, the code is as follows
Private Void Page_Load (Object Sender, System.EventArgs E)
{
SqlConnection
Conn
= New SQLCONNECTION ("Server = .; data = northwind; uid = sa; pwd = chengbo;");
Sqlcommand comm = new sqlcommand ();
Comm.Connection =
Conn
;
Comm.commandtype = commandtype.storedProcedure;
Comm.comMandText = "sp_select_allemployees";
Cn.open ();
SqldataReader Reader = Comm.ExecuteReader ();
DataGrid1.datasource = reader;
DataGrid1.databind ();
CONN.CLOSE ();
}
Press F5 to run, everything is normal.