Reputation: 3185
I have a SQL Server stored procedure that takes an IN
parameter and an OUT
parameter:
create PROCEDURE [dbo].[GetServiceByKeyword] @keyword nvarchar(30), @Service INT OUT
AS
BEGIN
SET NOCOUNT ON;
select @service = Service
from Keyword_Service
where Keyword = @keyword
END
I'm calling it in vb.net like this:
If cn.State = ConnectionState.Closed Then cn.Open()
cm = New SqlCommand("dbo.getservicebykeyword", cn)
cm.CommandType = Data.CommandType.StoredProcedure
cm.Parameters.AddWithValue("@keyword", id)
Dim Srvce As New SqlParameter("@Service", Data.SqlDbType.Int)
Srvce.Direction = Data.ParameterDirection.Output
cm.Parameters.Add(Srvce)
How can I use the output from this stored procedure? (Srvce
)
Its the first time I use OUT parameters and I wanna transform the result to String to be able to use it in the code.
Any help would be appreciated
Upvotes: 2
Views: 4237
Reputation: 6794
after calling cm.Execute(), you can get the value using:
dim result=cm.Parameters("@Service").Value
hope it will help you
regards
Upvotes: 3