Question Login Problem

maliken

New member
Joined
Nov 17, 2009
Messages
2
Programming Experience
Beginner
Hi guys i very new to this. When i saw vs 2008 had this login function ( under login) for vb.net i tested it but couldnt get it to work. upon enter in the user name and password they gave "IndexOutOfRangeException" on the red line.

VB.NET:
 Protected Sub Login1_Authenticate1(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        If YourValidationFunction(Login1.UserName, Login1.Password) Then
             MessageLabel.Text = "Successfully Logged In"
        Else

        End If
    End Sub

VB.NET:
 Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean

        Dim boolReturnValue As Boolean = False

        'Dim strConnection As String = "server=localhost\sqlexpress;database=NorthWind;Integrated Security=True;"

        'Dim strConnection As String = "Data Source=localhost\sqlexpress;Initial Catalog=Northwind;Integrated Security=True"

        Dim strconnection As String = "Data Source=localhost\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;"

        Dim sqlConnection As New SqlConnection(strConnection)

        Dim SQLQuery As String = "SELECT CustomerID, Password FROM Customers"

        Dim command As New SqlCommand(SQLQuery, sqlConnection)

        Dim Dr As SqlDataReader

        sqlConnection.Open()

        Dr = command.ExecuteReader()

        While Dr.Read()

        [COLOR="Red"]    If (UserName = Dr("UserName").ToString()) And (Password = Dr("Password").ToString()) Then[/COLOR]

                boolReturnValue = True

            End If

            Dr.Close()

            Return boolReturnValue

        End While

        Return boolReturnValue

    End Function
 
Perhaps you are not getting any records back and therefore, username and password are empty. Try
VB.NET:
If Dr.HasRows Then
    While Dr.Read()

         If (UserName = Dr("UserName").ToString()) And (Password = Dr("Password").ToString()) Then

            boolReturnValue = True
 
         End If

    Dr.Close()
End If
 
hi after adding the Dr.HasRows Then , vs returned = true.

which means its retrieving data from database but wrong place ?
 

Latest posts

Back
Top