Use [northwind]
Go
/***** Object: storedprocedure [DBO]. [users_insert] script Date: 10/19/2009 22:26:16 ******/
Set ansi_nulls off
Go
Set quoted_identifier on
Go
Create procedure [DBO]. [users_insert]
(
@ Uuserid int output,
@ Uusername nvarchar (30 ),
@ Upassword nvarchar (50)
)
As
Insert into [DBO]. [users]
(
[U_username]
, [U_password]
)
Values
(
@ Uusername
, @ Upassword
)
-- Get the identity value
Set @ uuserid = scope_identity ()
========================================================== ================================
Declare @ ID int;
Exec users_insert @ ID output, 'aaa', 'aaa'
Select
@ ID;
========================================================== ==============================
Using (sqlcommand cmd = new sqlcommand ("proc_userinfo", con ))
14 {
15 // What is the function? Remember to call the stored procedure. This statement cannot be fewer.
16 cmd. commandtype = commandtype. storedprocedure;
17 // Add the input/output parameter type and input parameter value of the stored procedure
18 cmd. Parameters. Add ("@ username", sqldbtype. varchar, 50). value = username;
19 cmd. Parameters. Add ("@ PWD", sqldbtype. varchar, 50). value = PWD;
20 cmd. Parameters. Add ("@ Grade", sqldbtype. varchar, 50). value = Grade;
21 cmd. Parameters. Add ("@ count", sqldbtype. INT );
22 cmd. Parameters ["@ username"]. dbtype = dbtype. String;
23 // specify whether the parameter type is input or output
24 cmd. Parameters ["@ username"]. Direction = parameterdirection. input;
25 cmd. Parameters ["@ PWD"]. dbtype = dbtype. String;
26 // specify whether the parameter type is input or output
27 cmd. Parameters ["@ PWD"]. Direction = parameterdirection. input;
28 cmd. Parameters ["@ Grade"]. dbtype = dbtype. String;
29 // specify whether the parameter type is input or output
30 cmd. Parameters ["@ Grade"]. Direction = parameterdirection. input;
31 cmd. Parameters ["@ count"]. dbtype = dbtype. int32;
32 // specify whether the parameter type is input or output
33 cmd. Parameters ["@ count"]. Direction = parameterdirection. output;
34 // The stored procedure is similar to a query statement.
35 cmd. executescalar ();
36 // accept the returned values after the stored procedure is executed
37 n = (INT) cmd. Parameters ["@ count"]. value;