R
Rudy
Hello all!
I have a simple login page, but I get a "Object reference not set to an
instance of an object" error. But I only get the error when I put in a user
and a password from the user databse in SQL. When I put in a non-user name,
my little error message comes up like it should, and it wors fine. Here is
my code:
Function ValidateUser(ByVal uid As String, ByVal passwd As String) As
Boolean
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim retVal As Boolean = False
cnn = New SqlConnection("Server=localhost;" & _
"DataBase=IMS;" & "Integrated Security=SSPI")
cmd = New SqlCommand("Select * from users where uname = '" & uid &
"'", cnn)
cnn.Open()
dr = cmd.ExecuteReader
While (dr.Read())
If StrComp(dr.Item("Pwd"), passwd, 1) = 0 Then
retVal = True
End If
End While
cnn.Close()
ValidateUser = retVal
End Function
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Session("LogonID") = txtUser.Text
Session("Password") = txtPswd.Text
Dim strID As String
Dim strPwd As String
strID = txtUser.Text
strPwd = txtPswd.Text
If ValidateUser(strID, strPwd) Then
"""" If Session("LoginID").ToString = String.Empty Then""""
Session("LoginID") = strID
Session("Password") = strPwd
FormsAuthentication.RedirectFromLoginPage(strID, False)
End If
Else
lblError.Text = "Invalid Login User/Password."
End If
End Sub
Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Submit1.ServerClick
Session("LogonID") = txtUser.Text
Session("Password") = txtPswd.Text
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, False)
End Sub
End Class
The error I'm getting is getting tagged at this line "If
Session("LoginID").ToString = String.Empty Then" I put a few quoted around
it in the code so it's easy to see.
I know I'm doing something wrong, not sure what.
Thanks for the help!!!
Rudy
I have a simple login page, but I get a "Object reference not set to an
instance of an object" error. But I only get the error when I put in a user
and a password from the user databse in SQL. When I put in a non-user name,
my little error message comes up like it should, and it wors fine. Here is
my code:
Function ValidateUser(ByVal uid As String, ByVal passwd As String) As
Boolean
Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim retVal As Boolean = False
cnn = New SqlConnection("Server=localhost;" & _
"DataBase=IMS;" & "Integrated Security=SSPI")
cmd = New SqlCommand("Select * from users where uname = '" & uid &
"'", cnn)
cnn.Open()
dr = cmd.ExecuteReader
While (dr.Read())
If StrComp(dr.Item("Pwd"), passwd, 1) = 0 Then
retVal = True
End If
End While
cnn.Close()
ValidateUser = retVal
End Function
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSubmit.Click
Session("LogonID") = txtUser.Text
Session("Password") = txtPswd.Text
Dim strID As String
Dim strPwd As String
strID = txtUser.Text
strPwd = txtPswd.Text
If ValidateUser(strID, strPwd) Then
"""" If Session("LoginID").ToString = String.Empty Then""""
Session("LoginID") = strID
Session("Password") = strPwd
FormsAuthentication.RedirectFromLoginPage(strID, False)
End If
Else
lblError.Text = "Invalid Login User/Password."
End If
End Sub
Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Submit1.ServerClick
Session("LogonID") = txtUser.Text
Session("Password") = txtPswd.Text
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, False)
End Sub
End Class
The error I'm getting is getting tagged at this line "If
Session("LoginID").ToString = String.Empty Then" I put a few quoted around
it in the code so it's easy to see.
I know I'm doing something wrong, not sure what.
Thanks for the help!!!
Rudy