Using Output Parameters With Enterprise Library 2.0

I couldn’t find a quick example when I was looking for one, so here’s mine.

First, create your stored procedure with an output parameter:

(@MyParameter varchar(50) OUTPUT)

And in your sproc, set your parameter to a value

set @MyParameter = scope_identity

Then, add an output parameter to your database command:

Dim _db As Database = DatabaseFactory.CreateDatabase
Dim _cmd As DbCommand = _db.GetStoredProcCommand(“MySproc”)
_db.AddOutParameter(_cmd, “@MyParameter”, DbType.Int32, 4)

Then, execute your stored procedure, and assign the parameter value to a variable (remember to DIM the variable)

_result = _db.GetParameterValue(_cmd, “@MyParameter”)