Login Form in Visual Basic 2010 and Access Database
-
07-08-2022 - |
Question
When trying to login on my system I get a "COMexception was unhandled" error on the line that contains:
DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;"
This is the code for the function that searches the database:
Public Function Login()
Dim DBConn As New ADODB.Connection
Dim User As New ADODB.Recordset
Dim Username As String
Dim UserDB As String
Dim PassDB As String
Dim UserFound As Boolean
DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & "DataSource = '" & Application.StartupPath & "\LoginDB.mdb'")
User.Open("UserTable", DBConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
UserFound = False
Login = False
Username = "Username = '" & txtboxUsername.Text & "'"
Do
User.find(Username)
If User.BOF = False And User.EOF = False Then
UserDB = User.Fields("Username").Value.ToString
PassDB = User.Fields("Password").Value.ToString
If UserDB <> txtboxUsername.Text Then
User.movenext()
Else
UserFound = True
If PassDB = txtboxPassword.Text Then
User.Close()
DBConn.Close()
Return True
Else
LoginError = "Invalid Password"
User.Close()
DBConn.Close()
Return False
End If
End If
Else
LoginError = "Invalid Username"
User.Close()
DBConn.Close()
Return False
End If
Loop Until UserFound = True
End Function
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow