03. juni 2003 - 14:23Der er
10 kommentarer og 1 løsning
Login spm?
Hejsa....
Sidder her med et lille login problem! Jeg for en følgende error: Object reference not set to an instance of an object
Kan ikke finde ud af hvor det går galt!
Min kode er nedenfor.
User Dbaccess class -----------------------------------------------------------
Public Function ValidateUser(ByVal sEmailAddress As String, ByVal sPassword As String) As Boolean Dim oDataAccess As New DbObject() Dim oConnection As SqlConnection = oDataAccess.GetConnection() Dim oCommand As New SqlCommand() Dim oDataReader As SqlDataReader Try With oCommand .CommandText = "sp_ValidateLogin" .CommandType = CommandType.StoredProcedure .Parameters.Add("@EmailAddress", sEmailAddress) .Parameters.Add("@Password", sPassword) .Connection = oConnection .ExecuteReader() End With If oDataReader.Read = False Then ValidateUser = False Else ValidateUser = True End If Finally oConnection.Close() End Try End Function
----------------------------------------------------------- User Business class
Public Function ValidateUser(ByVal sEmailAddress As String, ByVal sPassWord As String) As Boolean Dim oData As New DataCollection.User() If oData.ValidateUser(sEmailAddress, sPassWord) = True Then ValidateUser = True Else ValidateUser = False End If End Function
----------------------------------------------------------- event handler på code-behind siden
Public Sub cmdLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdLogin.Click
Dim oValidate As New Library.User() If oValidate.ValidateUser(txtEmailAddress.Text, txtPassword.Text) Then lblLoginResult.Text = "Login correct for " & txtEmailAddress.Text lblLoginResult.Visible = True Else lblLoginResult.Text = "Login failed for " & txtEmailAddress.Text lblLoginResult.Visible = True End If End Sub
bruger man ikke kun "then" hvis eventen kun omhandler en ting? Jeg plejer bare at skrive If oValidate.ValidateUser(txtEmailAddress.Text, txtPassword.Text) lblLoginResult.Text = "Login correct for " & txtEmailAddress.Text lblLoginResult.Visible = True Else lblLoginResult.Text = "Login failed for " & txtEmailAddress.Text lblLoginResult.Visible = True End If
men okay, jeg er ikke ligefrem ekspert :) et forsøg værd eh?
Den fejl kommer altid når du forsøger at kalde methods eller properties på et objekt der er nothing. Hvis jeg ikke tager meget fejl indeholder oValidate ikke noget.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.