using System.Data.SqlClient; SqlCommand cmd = new SqlCommand("storedProcedureName", connection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@paramName", SqlDbType.NVarChar, 50); param.Value = "parameter value"; param.Direction = ParameterDirection.Input; cmd.Parameters.Add(param); cmd.ExecuteNonQuery();
using System.Data.SqlClient; SqlCommand cmd = new SqlCommand("storedProcedureName", connection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@paramName", SqlDbType.NVarChar, 50); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); string outputValue = cmd.Parameters["@paramName"].Value.ToString();
using System.Data.SqlClient; SqlCommand cmd = new SqlCommand("storedProcedureName", connection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@paramName", SqlDbType.NVarChar, 50); param.Value = "input parameter value"; param.Direction = ParameterDirection.InputOutput; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); string outputValue = cmd.Parameters["@paramName"].Value.ToString();This example sets the direction of the parameter to InputOutput - this means that the parameter is both input and output parameter. It executes the stored procedure which updates the parameter value and then retrieves the output parameter value after the execution. The package library that contains the ParameterDirection enumeration is System.Data.SqlClient. This namespace provides data access to SQL Server databases using the .NET Framework.