vb.net中的存储过程语法结构

时间:2012-01-08 19:08:42

标签: asp.net sql-server vb.net ado.net

这是我的存储过程

 Create PROCEDURE dbo.veriftest
 @valueGuid varchar(50), 
 @message int Output
 AS
 Begin


 DECLARE @SelectValue varchar(50)

 select @SelectValue = code FROM test WHERE code=@valueGuid; 

 If @valueGuid=@SelectValue 
 BEGIN
 DELETE code FROM test WHERE code=@valueGuid ;
 SET @message = 0
 END
 Else 
 BEGIN
 Set @message = 1
 END


 END

这是vb代码

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim connectionString As String = WebConfigurationManager.ConnectionStrings("BecsEtMuseauxSQL").ConnectionString
    Dim con As SqlConnection = New SqlConnection(connectionString)
    Dim cmd As New SqlCommand("veriftest", con)
    cmd.CommandType = CommandType.StoredProcedure
    Dim objParameter As New SqlParameter("@valueGuid", SqlDbType.NVarChar, 15)
    cmd.Parameters.Add(objParameter)
    objParameter.Direction = ParameterDirection.Input
    objParameter.Value = TextBox1.Text

    Dim returnvalue As New SqlParameter("@message", SqlDbType.Int, 0)
    returnvalue.Direction = ParameterDirection.Output
    cmd.Parameters.Add(returnvalue)
    con.Open()

    cmd.ExecuteNonQuery()
    Dim count As Integer = Int32.Parse(cmd.Parameters("@message").Value.ToString())
    Label1.Text = count
    con.Close()
End Sub

执行存储过程时遇到麻烦(cmd.ExecuteNonQuery())表示对象名称代码无效....

我真的不明白我只想在我的label1中捕获输出@messase ......

vb.net中的此ID

由于

1 个答案:

答案 0 :(得分:3)

您需要将存储过程中的删除语句更改为:

DELETE FROM test WHERE code=@valueGuid

您还可以提高存储过程效率:

Create PROCEDURE dbo.veriftest
 @valueGuid varchar(50), 
 @message int Output
 AS
 Begin
   DELETE code FROM test WHERE code=@valueGuid
   SET @message = @@ROWCOUNT

 END