A small example of calling the SQL Server Stored Procedure in. net
Source: Internet
Author: User
First, when creating a stored procedure in sqlserver, there are parameters and no parameters in the call. First, let's briefly introduce the absence of parameters:
Assume that the stored procedure is as follows:
Copy codeThe Code is as follows: create proc selectall
As
Select * from studentinf
The call of this sp is as follows:
Sqlcommand selectcmd = new sqlcommand ("selectall", conn );
// Conn is sqlconnection
Selectcmd. commandtype = commandtype. storedprocedure;
To add a result set to a dataadapter, you can:
Sqldataadapter studa = new sqldataadapter ();
Studa. selectcommand = selectcmd;
If there is a parameter: create proc andselect
@ Studentid varchar (10 ),
@ Studentname varchar (10 ),
As
Select * from studentinf where studentid = @ studentid and studentname = @ studentname
You can add the following parameters:
Selectcmd. parameters. add ("@ studentid", sqldbtype. nvarchar, 10 );
Selectcmd. parameters. add ("@ studentname", sqldbtype. nvarchar, 10 );
If there is only one parameter, you can assign a value as follows:
Sqlparameters onepara = selectcmd. parameters. add ("@ studentid", sqldbtype. nvarchar, 10 );
Onepara. value = "a string"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.