所以我想从数据库中删除guid @value
并从我的存储过程中检索返回值
这是我的存储过程
ALTER PROCEDURE dbo.verifGuids
@value char(36),
@message char(1)Output
AS
Begin
DECLARE @SelectValue char(36)
select @SelectValue = value FROM guids WHERE @value=value;
If @value=@SelectValue
BEGIN
DELETE value FROM guids WHERE @value=value ;
SET @message = 0
END
Else
BEGIN
Set @message = 1
END
Return @message
END
这是我在asp.net中的vb.code
Dim guids As String = (Request.QueryString("ID"))
'stored procedure get Guid
Dim intRowsAff As Integer
Dim connectionString As String = WebConfigurationManager.ConnectionStrings("BecsEtMuseauxSQL").ConnectionString
Dim con As SqlConnection = New SqlConnection(connectionString)
Dim cmd As New SqlCommand("verifGuids", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@value", SqlDbType.Char, 36).Value = guids
Dim returnvalue As New SqlParameter("@message", SqlDbType.Char, 1)
returnvalue.Direction = ParameterDirection.Output
cmd.Parameters.Add(returnvalue)
Try
cmd.Connection.Open()
intRowsAff = cmd.ExecuteNonQuery()
Dim retour As String = (cmd.Parameters("@message").Value.ToString())
If retour = 0 Then
InformationLabel.Text = "Votre compte à été vérifier vous pouver vous connecter sur le site"
Else
InformationLabel.Text = "Votre compte n'est pas aprouvé veuiller vérifier dans vos mail le message de confirmation de votre compte "
End If
Catch ex As Exception
InformationLabel.Text = ex.Message & ex.Source & intRowsAff '& " record(s) inserted"
End Try
cmd.Connection.Close()
End If
我发现错误
对象名称'value'无效..Net SqlClient Data Provider0
我不明白我做错了什么......
这是在Vb.net ...
由于
答案 0 :(得分:2)
我认为您的存储过程代码中存在错误:
select @SelectValue = value FROM guids WHERE @value=value;
这是错的 - 它应该是
SELECT @SelectValue = value FROM guids WHERE value = @value
同样在这里:
DELETE value FROM guids WHERE @value=value ;
您必须将列(value
)与传入(@value
)的参数进行比较,而不是相反!所以改成这个:
DELETE FROM guids WHERE value = @value
你应该没问题
你的存储过程太复杂了......你可以把它简化为:
ALTER PROCEDURE dbo.verifGuids
@value char(36),
@message char(1) OUTPUT
AS
BEGIN
-- this will *already* delete only if the "value" column matches your "@value"
-- parameter - there's really no need to first do a SELECT on that table to
-- verify that!
DELETE FROM dbo.guids WHERE value = @value;
IF @@ROWCOUNT > 0
SET @message = 0 -- if you deleted anything - the set @message to "0"
ELSE
SET @message = 1
RETURN @message
END
答案 1 :(得分:0)
您必须使用Out参数作为返回值。你可以参考这个网站 Parameter Directions,您也可以查看MSDN Documentaion
答案 2 :(得分:0)
您需要将存储过程中的删除语句更改为:
DELETE FROM test WHERE code=@valueGuid
答案 3 :(得分:0)
将您的ParameterDirection.Output
更改为ParameterDirection.ReturnValue