Ok so basically I have a login form connected to a database and it (Database) contains my usernames and passwords. I also included a security level so that if a certain member logs on, features to them will be disabled. So For example if Katie logged in she can view all records BUT cannot delete them.
However there is a problem, each time I try to log in the following message appears:
"object reference not set to an instance of an object" either that message appears or this one:
"not allowed to change the 'connectionstring' property. the connection's current state is open."
I've been trying to solve this problem for a while now and I can't fix it.
Any help on this would be great.
However there is a problem, each time I try to log in the following message appears:
"object reference not set to an instance of an object" either that message appears or this one:
"not allowed to change the 'connectionstring' property. the connection's current state is open."
I've been trying to solve this problem for a while now and I can't fix it.
Below is the code for my login form:
Code:
Imports System.Data.OleDb
Public Class frmLogin
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDbDataAdapter
Dim sql As String
Dim dt As New DataTable
Dim DReader As OleDbDataReader
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'Dim dr As DataRow
Dim dr As OleDbDataReader
'Dim dt As DataTable
Dim user As String = Trim(txtUsername.Text)
Dim pword As String = Trim(txtPassword.Text)
' If the username or password fields are empty then this displays an error message:
If user = "" Then
MessageBox.Show("Please enter the username.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf pword = "" Then
MessageBox.Show("Please enter the password.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If user <> "" And pword <> "" Then
End If
dbSource = "Data Source =G:\Assignment 2 codes\ValleyMilk.accdb"
dbProvider = "PROVIDER = Microsoft.Ace.OLEDB.12.0;"
Try
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "SELECT * FROM Users WHERE Username= user AND [Password]= pword"
Dim cmd As OleDbCommand = New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("Username", user)
cmd.Parameters.AddWithValue("Password", pword)
dr = cmd.ExecuteReader
' If dr.Read() = True And user = dr("Username").ToString And pword = dr("Password").ToString Then
'LogginUserLevel and LoggedinUser are from Module1.vb
LoggedinUserLevel = DReader("SecurityLevel")
LoggedinUser = DReader("Username")
If dr.Read() = True Then
MsgBox("Welcome back !")
Me.Hide()
frmMainMenu.Show()
Else
MsgBox("Login Failure")
dr.Close()
con.Close()
End If
Catch errObj As Exception
MessageBox.Show(errObj.Message)
End Try
Any help on this would be great.