When I try debugging this, it comes up with an error on the line "If txtUsername.Text = ds.Tables("AddressBook").Rows(inc).Item(1) Then". It says NullReferenceException was unhandled. Object reference not set to an instance of an object.

Public Class MainLogin
Dim MaxRows As Integer
Dim inc As Integer = 0
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dbPassword As String
Dim sql As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim LoginCorrect As Boolean = False
Dim NoRecordsLeft As Boolean = False

 Private Sub MainLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    dbProvider = "provider=Microsoft.ACE.OLEDB.12.0"
    dbSource = "Data Source = G:\Sixth Form\Computing\Year 13\COMP4 - Project\Program Draft\DatabaseTest.accdb;" 'check drive letter before debugging
    dbPassword = "Jet OLEDB:Database Password=database;"
    con.ConnectionString = dbProvider & dbSource & dbPassword

    con.Open()

    sql = "SELECT * FROM tblPassword"
    da = New OleDb.OleDbDataAdapter(Sql, con)
    da.Fill(ds, "AddressBook")
    con.Close()
End Sub

Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
    Do
        If txtUsername.Text = ds.Tables("AddressBook").Rows(inc).Item(1) Then
            If txtPassword.Text = ds.Tables("AddressBook").Rows(inc).Item(2) Then
                LoginCorrect = True
            Else
                LoginCorrect = False
            End If
        Else
            LoginCorrect = False
        End If
        inc = inc + 1
        If inc = ds.Tables("AddressBook").Rows.Count Then
            NoRecordsLeft = True
        End If
    Loop Until LoginCorrect = True Or NoRecordsLeft = True
    If LoginCorrect = True Then
        MessageBox.Show("You have succesfully logged in correctly!!", "WOOOOOOOOOOOOO!")
    End If
    If NoRecordsLeft = True Then
        MessageBox.Show("Wrong username or password, please try again!!")
    End If
End Sub

Private Sub btnChangePassword_Click(sender As System.Object, e As System.EventArgs) Handles btnChangePassword.Click
    ChangePasswordBarcodeLogin.Show()
    Me.Hide()
End Sub

End Class

Try handling it with an inline if statment:

If txtUsername.Text = IIF(IsDBNull(ds.Tables("AddressBook").Rows(inc).Item(1)),"",ds.Tables("AddressBook").Rows(inc).Item(1)) Then
   'Do Work
End IF

It is possible that you are returning a null entry from the database, thus throwing a NRE.

By using this inline if, you return "" for null (not throwing a NRE) and can then debug it with:

MsgBox(IIF(IsDBNull(ds.Tables("AddressBook").Rows(inc).Item(1)),"",ds.Tables("AddressBook").Rows(inc).Item(1)))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.