Knight Data Access Layer
Executing With Output Parameters
Basic Tasks C# > Database Commands > Executing With Output Parameters

Here is an example of how to execute a stored procedure with output parameters:

 

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

string storedProcedure = "Insert_Customer";

 

//Parameters

List<IDbDataParameter> parameters = new List<IDbDataParameter>();

IDbDataParameter primaryKeyOutput = new System.Data.SqlClient.SqlParameter("@CustomerId",DbType.Int64);

primaryKeyOutput.Direction = ParameterDirection.Output;

parameters.Add(primaryKeyOutput);

 

int affectedRecords = db.ExecuteNonQuerySproc(storedProcedure, parameters);

 

Console.WriteLine(parameters[0].Value);