Stored Procedures
To enable stored procedures in the application, do the following:
•
Set the CommandText property in the PsqlCommand object to the stored procedure name.
MyCommand.CommandText = "GetEmpSalary";
•
Set the CommandType property in the PsqlCommand object to StoredProcedure.
MyCommand.CommandType = CommandType.StoredProcedure;
•
Specify parameter arguments, if needed. The application should add the parameters to the parameter collection of the PsqlCommand object in the order of the arguments to the stored procedure. The application does not need to specify the parameter markers in the CommandText property of the PsqlCommand object.
To retrieve the return value from a stored procedure, the application should add an extra parameter to the parameter collection for the PsqlCommand object. This parameter’s ParameterDirection property should be set to ParameterDirection.ReturnValue. The return value parameter can be anywhere in the parameter collection because it does not correspond to a specific parameter marker in the Text property of the PsqlCommand object.
If the stored procedure does not produce a return value, parameters bound with the ParameterDirection property as ReturnValue are ignored.
If the stored procedure returns a ReturnValue from the database and the application has not bound a parameter for it, the data provider discards the value.
NOTE FOR ADO.NET ENTITY FRAMEWORK USERS: The PsqlConnection object includes properties and methods that provide enhanced statistics functionality. The methods and properties are standard in the ADO.NET data provider, but are not available at the ADO.NET Entity Framework layer. Instead, the ADO.NET Entity Framework data provider exposes the same functionality through "pseudo" stored procedures. See
Using Stored Procedures with the ADO.NET Entity Framework
for more information.