PC Review


Reply
Thread Tools Rate Thread

customValidator troubles

 
 
Philip Korolev
Guest
Posts: n/a
 
      26th Nov 2004
Hi All.

What I am trying to do is use customValidator to go to a database via a stored procedure and fish out a UserName value. If it finds it, I want it to return 1 and if not I want it to return 0. On the ASP.NET page I have a field called user_username that customValidator is pointing to as a control to validate. The subroutine for the validator and my stored procedure are below. I now have 37 instances of the username = pkorolev and I get 37 as the value returned by the stored procedure, however the point where I want it to invalidate the page, the code fails. What am I missing???? I bet it is something really simple.
***********************
create procedure userAlreadyExists
@user_username nvarchar(100),
@valid int output
as
declare @userValid int

select @userValid = Count(*) from user_pass
where user_username = @user_username


set @Valid = convert(int, @userValid) -- in this line i am simply trying to ensure that the value coming back as an iteger


**********************


CustomValidator SUB:



*********************


Private Sub custValUserExists_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles custValUserExists.ServerValidate

Dim cnn As New SqlConnection(connection.SQlConnection)

Dim sdrUserExists As SqlDataReader

Dim cmdUserExists As New SqlCommand("userAlreadyExists", cnn)

Dim ctrlValue As Integer

Try

cnn.Open()

cmdUserExists.CommandType = CommandType.StoredProcedure

cmdUserExists.Parameters.Add("@user_username", SqlDbType.NVarChar, 100).Direction = ParameterDirection.Input

cmdUserExists.Parameters("@user_username").Value = Trim(art_username.Text)

cmdUserExists.Parameters.Add("@Valid", SqlDbType.Int).Direction = ParameterDirection.Output

cmdUserExists.ExecuteNonQuery()

'the line below is for checking the value returned on the confirmation page
Session("DBRETVAL") = cmdUserExists.Parameters("@Valid").Value

If cmdUserExists.Parameters("@Valid").Value = 0 Then

args.IsValid = True

Else

args.IsValid = False

End If

Catch ex As Exception

lbltype.Text = ex.ToString

End Try

End Sub

*******************************



Many thanks

Phil

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CustomValidator Stan SR Microsoft ASP .NET 3 8th May 2007 02:30 PM
CustomValidator Philip Korolev Microsoft Dot NET 2 1st Dec 2004 09:35 AM
CustomValidator Control troubles Philip Korolev Microsoft Dot NET 0 25th Nov 2004 07:28 PM
Login Troubles and Start Menu troubles Jono Windows XP Help 2 30th Jul 2004 03:12 PM
CustomValidator =?Utf-8?B?VG9t?= Microsoft ASP .NET 1 27th Feb 2004 01:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 AM.