Hi Guys,
First of all thanks to all of them who responded for this question.
I solved above issues with below solutions:
SQL Procedure:
I created one procedure in SQL server 2005
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[uspUpdateAllocateToken]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[uspUpdateAllocateToken]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[uspUpdateAllocateToken]
( @CPUserID INT)
AS
IF NOT EXISTS(SELECT TokenID FROM tblToken WHERE CPUserId=@CPUserID AND StatusID IN (41,47))
BEGIN
UPDATE tblToken
SET
CPUserID = @CPUserID,
StatusID=47
WHERE
tblToken.TOKENID = (SELECT TOP 1 TOKENID FROM TBLTOKEN WHERE CPUSERID IS NULL AND STATUSID = 40)
END
Further in my application on my Button Click. I write below code:
Protected Sub ibtnAllocateTokens_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtnAllocateTokens.Click
Try
Dim conString As String = WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
Dim con As New SqlConnection(conString)
con.Open()
Dim cmd As SqlCommand
For Each gvRow As GridViewRow In GridView1.Rows
cmd = New SqlCommand("uspUpdateAllocateToken", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@CPUserID", SqlDbType.Int).Value = CType(gvRow.Cells(1).FindControl("lblCPUserID"), Label).Text
cmd.ExecuteScalar()
lblAllocateTokenMessage.Visible = True
Next
Catch ex As Exception
ErrorHandler.WriteError(ex.Message)
End Try
End Sub
Please have a look and let me know if there seems any problem in this implementation.
Cheers!