How to get the output parameter from Store Procedure ?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I try to set an output parameter to get the result from store procedure,
However,Do I still need to loop the reader to get result ?? Thanks a lot

cmdKey.Parameters("@result").Direction = ParameterDirection.Output

Dim drCntrId As SqlDataReader =
cmdKey.ExecuteReader(CommandBehavior.SingleRow)
While drCntrId.Read
strKey = drCntrId.Item("result")
End While
 
Output params are not available until the data reader is closed. So, close
the drCntrlId first and then access the output value as
cmdKey.Parameters("@result").Value

You can use SqlCommand.ExecuteNonQuery() instead of ExecuteReader unless you
return rows from the stored proc.

HTH

I try to set an output parameter to get the result from store procedure,
However,Do I still need to loop the reader to get result ?? Thanks a lot

cmdKey.Parameters("@result").Direction = ParameterDirection.Output

Dim drCntrId As SqlDataReader =
cmdKey.ExecuteReader(CommandBehavior.SingleRow)
While drCntrId.Read
strKey = drCntrId.Item("result")
End While
 
Back
Top