ParamValue.Output<TType>(string name) Method
.NET Standard 2.x
Creates a new ParamValue
object as the output parameter of a stored procedure.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static ParamValue Output<TType>(string name)
Type Parameters
TType
The datatype of the parameter value.
Parameters
name
System.String
The name of the parameter.
Returns
Returns a newly created ParamValue
object.
Examples
The following code example creates a ParamValue
object and specifies its name and Output direction, then uses it together with SqlExecutor
.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Data;
namespace Appeon.ApiDoc.ParamValueExamples
{
public class OutputExample
{
private readonly SchoolContext _context;
public OutputExample(SchoolContext context)
{
_context = context;
}
public void Example1()
{
// Sets the parameter values.
// The parameter direction defaults to ParameterDirection.Input,
// so you can omit it.
var idParam = ParamValue.New<string>("id", "4");
// The parameter 'Name' is Output type.
var nameParam = ParamValue.Output<string>("name");
// Specifies the procedure to be executed.
var procedureName = "GetDepartmentName";
/* StoredProcedure GetDepartmentName:
CREATE PROCEDURE[dbo].[GetDepartmentName]
@ID int,
@Name nvarchar(50) OUTPUT
AS
SELECT @Name = Name FROM Department
WHERE DepartmentID = @ID
GO
*/
// Executes the SQL statement and gets the department by nameParam.
_context.SqlExecutor.ExecuteProcedure(
procedureName, idParam, nameParam);
Console.WriteLine("Department Name: {0}", nameParam.Value);
/*This code produces the following output:
Department Name: Economics
*/
}
}
}
Applies to
.NET Standard
2.x