Hi all,
I setup a form that allows the user to change the password. This password is stored in a Database (MSAccess) and the table name is Admin. There's only one field in it, named Passwd.
When i run the program, i constantly get above error message "Object reference not set to an instance of an object.". There's a prompt that appears, where i have to select Break or Continue. When i click on the Continue, the program stops at a specific line. Please see below the coding. The error is at the line showing "dbConn.Open()"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bol As Boolean
Dim dr As DataRow
If TextBox1.Text = "" Then
MsgBox("Old Password Must Be Filled !", MsgBoxStyle.Critical, "Sales System")
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text = "" Then
MsgBox("New Password Must Be Filled !", MsgBoxStyle.Critical, "Sales System")
TextBox2.Focus()
Exit Sub
End If
PasswordKeyin = TextBox1.Text
bol = False
If PasswordKeyin <> "" Then
For Each dr In PasswdUtil_DataSet.Tables(0).Rows
If dr("Passwd") = PasswordKeyin Then
bol = True
End If
Next dr
End If
If bol = True Then
dbConn.Open() '<<----- Error is here
PasswdUtil_SQLCommand = "UPDATE Admin SET Passwd= '" & TextBox2.Text & "' WHERE Passwd = '" & TextBox1.Text & "' "
Dim cmd As New OleDbCommand(PasswdUtil_SQLCommand, dbConn)
cmd.ExecuteNonQuery()
MsgBox("Password Saved Successfully !", MsgBoxStyle.Information, "Sales System")
dbConn.Close()
Me.Close()
Else
MsgBox("Your Old Password Is Wrong !", MsgBoxStyle.Critical, "Sales System")
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End If
End Sub
=====
The Form name is PasswdUtil_Form, and i have this loading event as well.
Private Sub PasswdUtil_Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Make The Data Adapter
PasswdUtil_DataAdapter = New OleDbDataAdapter(PasswdUtil_SQLCommand, ConStr)
'Map The default Name Table
PasswdUtil_DataAdapter.TableMappings.Add("Table", "Admin")
'Clear then Fill the Data Set
PasswdUtil_DataSet.Clear()
Try
PasswdUtil_DataAdapter.Fill(PasswdUtil_DataSet)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
=============
In my Module section , i have these;
Public DBPath As String = System.Configuration.ConfigurationSettings.AppSettings("DbLocation")
Public ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
Public dbConn As OleDbConnection
=======
Could any body advise me why i constantly get this error message ?
Thank you
Salim
I setup a form that allows the user to change the password. This password is stored in a Database (MSAccess) and the table name is Admin. There's only one field in it, named Passwd.
When i run the program, i constantly get above error message "Object reference not set to an instance of an object.". There's a prompt that appears, where i have to select Break or Continue. When i click on the Continue, the program stops at a specific line. Please see below the coding. The error is at the line showing "dbConn.Open()"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bol As Boolean
Dim dr As DataRow
If TextBox1.Text = "" Then
MsgBox("Old Password Must Be Filled !", MsgBoxStyle.Critical, "Sales System")
TextBox1.Focus()
Exit Sub
End If
If TextBox2.Text = "" Then
MsgBox("New Password Must Be Filled !", MsgBoxStyle.Critical, "Sales System")
TextBox2.Focus()
Exit Sub
End If
PasswordKeyin = TextBox1.Text
bol = False
If PasswordKeyin <> "" Then
For Each dr In PasswdUtil_DataSet.Tables(0).Rows
If dr("Passwd") = PasswordKeyin Then
bol = True
End If
Next dr
End If
If bol = True Then
dbConn.Open() '<<----- Error is here
PasswdUtil_SQLCommand = "UPDATE Admin SET Passwd= '" & TextBox2.Text & "' WHERE Passwd = '" & TextBox1.Text & "' "
Dim cmd As New OleDbCommand(PasswdUtil_SQLCommand, dbConn)
cmd.ExecuteNonQuery()
MsgBox("Password Saved Successfully !", MsgBoxStyle.Information, "Sales System")
dbConn.Close()
Me.Close()
Else
MsgBox("Your Old Password Is Wrong !", MsgBoxStyle.Critical, "Sales System")
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End If
End Sub
=====
The Form name is PasswdUtil_Form, and i have this loading event as well.
Private Sub PasswdUtil_Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Make The Data Adapter
PasswdUtil_DataAdapter = New OleDbDataAdapter(PasswdUtil_SQLCommand, ConStr)
'Map The default Name Table
PasswdUtil_DataAdapter.TableMappings.Add("Table", "Admin")
'Clear then Fill the Data Set
PasswdUtil_DataSet.Clear()
Try
PasswdUtil_DataAdapter.Fill(PasswdUtil_DataSet)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
=============
In my Module section , i have these;
Public DBPath As String = System.Configuration.ConfigurationSettings.AppSettings("DbLocation")
Public ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
Public dbConn As OleDbConnection
=======
Could any body advise me why i constantly get this error message ?
Thank you
Salim