从表中选择一个值以插入到新表中以及其他值

时间:2014-11-22 21:42:48

标签: sql .net sql-server-2014

我有这个存储过程不会返回带有@RefereeId输出参数的getRefereeId。有什么建议?运行此查询时,getRefereeId没有返回任何内容

   @Email nvarchar(50),
   @AssignerId int,
   @RefereeId Int Output,
   @DateCreated Datetime,
   @Active bit,
   @Invitation bit
as
begin
    Select @RefereeId 
    From Referee 
    Where Email = @Email

    Insert Into Assignment (AssignerId, RefereeId, DateCreated, Active, Invitation) 
    Values (@AssignerId, @RefereeId, @DateCreated, @Active, @Invitation)
End

VB代码:

Dim strConn As String = "Data Source=mydatasource"
Dim Conn As New SqlConnection(strConn)

Dim Cmd As New SqlCommand("InviteReferee", Conn)
Cmd.CommandType = CommandType.StoredProcedure

Cmd.Parameters.Add(New SqlParameter("Email", newEmail.Text))        
Cmd.Parameters.Add(New SqlParameter("Invitation", "True"))
Cmd.Parameters.Add(New SqlParameter("Active", "False"))
Cmd.Parameters.Add(New SqlParameter("AssignerId", AssignerId.Text))
Cmd.Parameters.Add(New SqlParameter("DateCreated", DateTime.Now()))        

Dim getRefereeId As SqlParameter = Cmd.Parameters.Add("@RefereeId", SqlDbType.Int)
getRefereeId.Direction = ParameterDirection.Output

Conn.Open()
Cmd.ExecuteNonQuery()

1 个答案:

答案 0 :(得分:0)

您需要实际为输出参数指定列值!

将您的代码更改为:

Select @RefereeId = SomeSuitableColumnNameHere
From dbo.Referee 
Where Email = @Email

这样,您将在Referee中选择一个列到@RefereeId参数中,然后将其发送回VB.NET调用者。