示例下面的示例带有单个输入参数(客户 ID)并返回一个输出参数(该客户的总销售额)。CREATE PROCEDURE [dbo].[CustOrderTotal] @CustomerID nchar(5), @TotalSales money OUTPUT AS SELECT @TotalSales = SUM(OD.UNITPRICE*(1-OD.DISCOUNT) * OD.QUANTITY) FROM ORDERS O, "ORDER DETAILS" OD where O.CUSTOMERID = @CustomerID AND O.ORDERID = OD.ORDERID Visual Basic _ PublicFunction CustOrderTotal( ByVal customerID AsString, ByRef totalSales As System.Nullable(OfDecimal)) As IntegerDim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo), customerID, totalSales) totalSales = CType(result.GetParameterValue(1), System.Nullable(OfDecimal)) Return CType(result.ReturnValue, Integer) EndFunction C# [Function(Name="dbo.CustOrderTotal")] [return: Parameter(DbType="Int")] publicint CustOrderTotal([Parameter(Name="CustomerID", DbType="NChar(5)")] string customerID, [Parameter(Name="TotalSales", DbType="Money")] ref System.Nullable totalSales) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), customerID, totalSales); totalSales = ((System.Nullable)(result.GetParameterValue(1))); return ((int)(result.ReturnValue)); } 您将按如下方式调用此存储过程: Visual Basic Dim db AsNew Northwnd("C:\...\northwnd.mdf") Dim totalSales AsDecimal? = 0 db.CustOrderTotal("alfki", totalSales) Console.WriteLine(totalSales) C# Northwnd db = new Northwnd(@"c:\northwnd.mdf"); decimal? totalSales = 0; db.CustOrderTotal("alfki", ref totalSales); Console.WriteLine(totalSales);