c#使用输出参数调用存储过程 [英] c# calling stored procedure with output parameters

查看:196
本文介绍了c#使用输出参数调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果该过程明确返回错误代码并使用OUTPUT
参数如何访问both.like下面的示例,我是从Microsoft网站获取的.

If the procedure is returning explicitly the error code and using OUTPUT
parameter how to access both.like below example which i have taken from microsoft site.

USE Northwind
GO
-- Create a procedure that takes one input parameter
-- and returns one output parameter and a return code.
CREATE PROCEDURE SampleProcedure @EmployeeIDParm INT,
         @MaxQuantity INT OUTPUT
AS
-- Declare and initialize a variable to hold @@ERROR.
DECLARE @ErrorSave INT
SET @ErrorSave = 0

-- Do a SELECT using the input parameter.
SELECT FirstName, LastName, Title
FROM Employees
WHERE EmployeeID = @EmployeeIDParm

-- Save any nonzero @@ERROR value.
IF (@@ERROR <> 0)
   SET @ErrorSave = @@ERROR

-- Set a value in the output parameter.
SELECT @MaxQuantity = MAX(Quantity)
FROM [Order Details]

IF (@@ERROR <> 0)
   SET @ErrorSave = @@ERROR

-- Returns 0 if neither SELECT statement had
-- an error; otherwise, returns the last error.
RETURN @ErrorSave
GO

推荐答案

查看以下msdn站点.

http://msdn.microsoft.com/zh-cn/library/59x02y99%28v=vs.90%29.aspx

他们有一个带有输入,输出和返回的存储过程.并将其添加到sqlcommand时,为参数添加相应的方向.
Look into the below msdn site.

http://msdn.microsoft.com/en-us/library/59x02y99%28v=vs.90%29.aspx

They have a stored proc with input, output and return. And adding the corresponding directions for the parameters when adding it to sqlcommand.


这篇关于c#使用输出参数调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆