Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Visual Studio project with two forms
First to log in
The second is to change the username and password
I have a problem when I want to update my username and password
(System.Data.OleDb.OleDbException: 'Syntax error in UPDATE statement.')


What I have tried:

Imports System.Data.OleDb

Public Class User
    Public DA As New OleDbDataAdapter
    Public DT As New DataTable
    Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Abo Khallad\Desktop\Visual Studio VB.Net\Test VB.Net\Login User\bin\Debug\Notes.accdb"
    Dim Conn As New OleDbConnection(connectionString)
    Public ds1 As New DataSet
    Sub Fill_DGV()
        Dim dataAdapter As New OleDbDataAdapter("SELECT * FROM Login", connectionString)
        Dim dataSet As New DataSet()
        dataAdapter.Fill(dataSet)
        DataGridView1.DataSource = dataSet.Tables(0)
    End Sub

Private Sub FrmUser_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     TxtNewUser.Focus()
     TxtNewUser.Enabled = False
     TxtNewPass.Enabled = False
     BtnOk.Enabled = False
     Fill_DGV()
     Dim dt As New DataTable
     dt.Clear()
     DA = New OleDbDataAdapter("Select * from Login", Conn)
     DA.Fill(dt)
 End Sub

Private Sub BtnOk_Click(sender As Object, e As EventArgs)

    If TxtOldUser.Text = "" And TxtOldPass.Text = "" Then
        MsgBox("من فضلك ادخل اسم المستخدم وكلمة المرور)", MsgBoxStyle.MsgBoxRtlReading + MsgBoxStyle.MsgBoxRight + vbOKOnly, Title:="ملاحظة")
        Exit Sub
    End If
    Dim Cmd As New OleDbCommand("Update Login Set User = @User, Pass = @Pass Where User = @User", Conn)
    Dim User As String = TxtNewUser.Text
    Dim Pass As String = TxtNewPass.Text
    Cmd.Parameters.Add("@User", OleDbType.VarChar).Value = User
    Cmd.Parameters.Add("@Pass", OleDbType.VarChar).Value = Pass
    Conn.Open()
    Cmd.ExecuteNonQuery()
    Conn.Close()
End Sub
Posted
Updated 30-Mar-23 18:26pm

To add to what Patrice has said ... don't do it like that! Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

And remember: if you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.

And why are you retrieving all the Login info for all users when you load a user? There is another security problem just waiting for you to fall into it.
At the moment, it's not a major problem, because you discard the data as soon as you read it, but at some point you will actually use it, and at that point you risk exposing user data to everybody and there is a huge amount of Data Protection legislation around that!
 
Share this answer
 
Probably not your error, but
VB
Dim Cmd As New OleDbCommand("Update Login Set User = @User, Pass = @Pass Where User = @User", Conn)
' Here your want the new user id                     ^^^^^
' Here you want the actual user id, as used while login                               ^^^^
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900