I have a SQL Server stored procedure that takes an IN
parameter and an OUT
parameter:
我有一个SQL Server存储过程,它接受一个IN参数和一个OUT参数:
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:
我在vb.net中这样称呼它:
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
)
如何使用此存储过程的输出? (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.
它是我第一次使用OUT参数,我想将结果转换为String,以便能够在代码中使用它。
Any help would be appreciated
任何帮助,将不胜感激
1 个解决方案
#1
3
after calling cm.Execute(), you can get the value using:
在调用cm.Execute()之后,您可以使用以下命令获取值:
dim result=cm.Parameters("@Service").Value
hope it will help you
希望它能帮助你
regards
#1
3
after calling cm.Execute(), you can get the value using:
在调用cm.Execute()之后,您可以使用以下命令获取值:
dim result=cm.Parameters("@Service").Value
hope it will help you
希望它能帮助你
regards