I'm wondering what's wrong with the following codes I got below. I'm creating a form where a user can change their password but I always get an error whenever I try to run my system. Any help would be greatly appreciated! Thank you.
Public Class Form7
Dim cnString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\Thesis\Thesis\Database1.accdb"
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Using dbCommand As New System.Data.OleDb.OleDbCommand("select count ([Password]) from students where [Password] like ?", cnString)
dbCommand.Parameters.AddWithValue("@password", textbox1.Text)
Dim result As Integer = DirectCast(dbCommand.ExecuteScalar(), Integer)
If result = 1 Then
Dim sqlquery As String = "UPDATE students SET StudFacID = @STUDID, [Password] = @Password" & _
"WHERE ID = StudFacID"
' Use this form to initialize both connection and command to
' avoid forgetting to set the appropriate properties....
Using conn = New System.Data.OleDb.OleDbConnection(cnString)
Using cmd = New System.Data.OleDb.OleDbCommand(sqlquery, cnString)
cnString.Open()
cmd.Parameters.AddWithValue("@STUDID", TxtID.Text)
cmd.Parameters.AddWithValue("@Password", TextBox2.Text)
End Using
End Using
End If
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class