【解決方法】このコードの何が問題になっていますか?

[ad_1]

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.')

私が試したこと:

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

解決策 1

おそらくあなたのエラーではありませんが、

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                               ^^^^

[ad_2]

コメント

タイトルとURLをコピーしました