I wrote a SQL Server stored procedure based on my previous question that I asked which was answered that is why I am creating a new question.
STORED PROCEDURE
ALTER Procedure [dbo].[usp_validatecard](
@CLUBCARD1 nvarchar(50),
@STATUS nvarchar(50))
As
BEGIN
IF EXISTS(Select CLUBCARD1, STATUS
from dbo.clubmembers
where CLUBCARD1 = @CLUBCARD1 and STATUS = 'ACTIVE')
Print 'Card is GOOD'
ELSE
IF EXISTS(SELECT CLUBCARD1, STATUS
FROM dbo.clubmembers
where CLUBCARD1 = @CLUBCARD1 and STATUS = 'INACTIVE')
PRINT 'Card is good but not active'
ELSE
PRINT 'CARD NOT IN SYSTEM'
END
The trouble I am having is not too sure how to call that in VB. The code I have so far is this
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub cmdclick_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdclick.Click
Dim strConnString As String = WebConfigurationManager.ConnectionStrings("orca").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand("usp_validatecard", con)
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.Add("@CLUBCARD1", Data.SqlDbType.NVarChar).Value = txtvalidate.Text
Try
con.Open()
Dim Result As Integer = cmd.ExecuteNonQuery()
Catch ex As SqlException
lblmessage.Text = "Error"
Finally
con.Close()
End Try
End Sub
End Class
What I am trying to do is if the clubcard parameter is found and status is active I would like the label to read ‘card is good’ also if the clubcard parameter is found however is inactive then the label should read ‘card is good but not active’ last if all those fail just have the label read ‘card not in system’
As of right now this code does not work I thought I could just call the stored procedure and exec it and it would print the statements depending on what passes however it is erroring out.
When I debug it the error I get is under the cmd.parameters.add is
Item In order to evaluate an indexed
property, the property must be
qualified and the arguments must be
explicitly supplied by the user.
You can change your SP to
and in vb.net side,