Hi everyone Could someone please help me, I need to loop through all the records in a column in my access database, Currently my program only views the first record in the column and does not go any further, I tried a While loop but I get a NullException error and it says there is no data in my column, her is my code thus far.
Imports System.Data.OleDb
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Public Class form_Login
Dim dbReader As OleDbDataReader
Dim dbConnect As New OleDb.OleDbConnection
Dim dbCommand As OleDbCommand
Dim Line As String = Environment.NewLine
Dim ValidUser As Boolean
Dim CurrentUser As String = GetCurrent.Name
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
MessageBox.Show(CurrentUser)
dbReader = dbCommand.ExecuteReader
dbReader.Read()
If dbReader("Abnum") = CurrentUser Then
ValidUser = True
End If
MessageBox.Show(dbReader("Abnum"))
If ValidUser = True Then
Dim mainForm As New form_MainMenu
btnLogin.Enabled = False
mainForm.Show()
Me.Hide()
Else
lblMessage.Text = "You are not a Registered User for this Application"
End If
End Sub
Private Sub form_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
dbConnect.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Database\WorkWatchMain.mdb"
dbConnect.Open()
dbCommand = New OleDbCommand("SELECT * FROM Table_Login", dbConnect)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Abnum is my column name, if you were wondering, and don't worry about the connection, that works perfectly.