In front of a "CLR stored procedure with parameters" http://www.cnblogs.com/insus/p/4373605.html, if we need to create a return value with output.
Implement it, you can first understand the C # out keyword
Out (C # Reference)
Open the SQL DataBase project we wrote earlier and add a method:
To copy code:
Public Static voidGetfruitname ( outSqlString fruitname, SqlByte FRUIT_NBR) {SqlConnection Connection=NewSqlConnection ("Context connection=true"); Connection. Open (); SqlCommand Command=NewSqlCommand (); Command. Connection=connection; stringsql ="SELECT [fruitname] from [dbo]. [Fruit] WHERE [FRUIT_NBR] = @Fruit_nbr"; Command.commandtext=SQL; SqlParameter param=NewSqlParameter ("@Fruit_nbr", Sqldbtype.tinyint); Param. Value=FRUIT_NBR; Command. Parameters.Add (param); Try { stringScalarvalue = (string) command. ExecuteScalar (); Fruitname=(SqlString) Scalarvalue; } Catch{fruitname=string. Empty; } connection. Close (); }
View Code
Build solution, and then locate Microsoft SQL Server Management Studio, redeploy assembly, and CLR stored procedure.
Refer to the first two "simple creation and deployment of the CLR stored procedures" http://www.cnblogs.com/insus/p/4371762.html and "CLR stored procedures with parameters" http://www.cnblogs.com/insus/p/ 4373605.html
To execute a stored procedure:
CLR stored procedure with output parameters