Im trying to use the new login controls as well but not having any luck getting this to work. I want the user to type in their name and password and use a stored procedure to check and see if their information is correct. If it is, allow them on to the next page... if it isnt, make them attempt a login again. VS doesnt like this part of the page so far:
cmd.CommandType = CommandType.StoredProcedure
it says that the second commandtype is not declared but i have seen it written like this in examples on the web. Thanks in advance!
Code for the page so far:
ProtectedSub Login1_Authenticate(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.AuthenticateEventArgs)Handles Login1.Authenticate
Dim user_IDAsInteger
Dim conStringAsString = Pre_con &"Data Source=" & WebServer &"Initial Catalog=" & SDatabase
Dim myConnectionAs SqlConnection =New SqlConnection(conString)
myConnection.Open()
Dim cmd =New SqlCommand("spLogin", myConnection)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@dotnet.itags.org.LoginName", Login1.UserName.ToString)
cmd.Parameters.Add("@dotnet.itags.org.LoginCode", Login1.Password.ToString)
cmd.ExecuteNonQuery()
user_ID = (cmd.parameters("@dotnet.itags.org.cnt").value)
If user_ID > 0Then
Response.Redirect("default.aspx")
Else
Response.Redirect("login.aspx")
EndIf
cmd.Connection.Close()
cmd.Dispose()
EndSub
STORED PROCEDURE:
setANSI_NULLSON
setQUOTED_IDENTIFIERON
go
ALTERPROCEDURE [dbo].[spLogin]
(
@dotnet.itags.org.LoginNamevarchar(50),
@dotnet.itags.org.LoginCodevarchar(50),
@dotnet.itags.org.cntintoutput
)
AS
SELECT @dotnet.itags.org.cnt=PersonIDFROM Person
WHERE Person.LoginName=LoginNameAND Person.LoginCode=LoginCode
if @dotnet.itags.org.cnt<1
set @dotnet.itags.org.cnt=0
Most likely you are missing an IMPORTS call.Figured that out right after i posted essentially... (is there an embarressed emoticon i can enter here?) ;)
Still cant quite get it to work... This code generates this error:
"Procedure or Function 'spLogin' expects parameter'@.cnt', which was not supplied."
It is not supplied because that is what is supposed to be coming back from the stored procedure...
CODE:
ProtectedSub Login1_Authenticate(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.AuthenticateEventArgs)Handles Login1.Authenticate
'Dim user_ID As Integer
Dim conStringAsString = Pre_con &"Data Source=" & WebServer &"Initial Catalog=" & SDatabase
Dim myConnectionAs SqlConnection =New SqlConnection(conString)
myConnection.Open()
Dim cmd =New SqlCommand("spLogin", myConnection)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@.LoginName", Login1.UserName.ToString)
cmd.Parameters.Add("@.LoginCode", Login1.Password.ToString)
cmd.ExecuteNonQuery()
Dim user_IDAsInteger = cmd.Parameters("@.cnt").Value
If user_ID > 0Then
Response.Redirect("default.aspx")
Else
Response.Redirect("login.aspx")
EndIf
cmd.Connection.Close()
cmd.Dispose()
EndSub
declare and populate the param BEFORE you tell it to .Execute...
I tried moviing this line [Dim user_IDAsInteger = cmd.Parameters("@.cnt").Value]above [cmd.ExecuteNonQuery()] but i still get an error...
"An SqlParameter with ParameterName'@.cnt' is not contained by this SqlParameterCollection."
Is this an OUTPUT paramater?
You may want to google that one, IIRC you need to declare it as such
0 comments:
Post a Comment