访问数据库中的UPDATE语句vb.net中的语法错误

当我试图更新我的数据库时出现错误

UPDATE语句项中的语法错误:为了评估索引属性,该属性必须是限定的,并且参数必须由用户明确提供。 错误代码:-2147217900

错误:{System.Data.OleDb.OleDbErrorCollection}

导入System.Data.OleDb

公共类Ubah_Password Dim kns As New OleDbConnection(“provider = microsoft.ace.oledb.15.0; data source =”&Application.StartupPath&“ database.accdb”)Dim da As New OleDbDataAdapter Dim ds As New DataSet Dim sql As String

Sub tampilkan()     'menampilkan semua user
    ds.Clear()
    sql = "SELECT * FROM USERLIST"
    da.SelectCommand = New OleDbCommand(sql, kns)
    da.Fill(ds, "USERLIST")
End Sub

Sub cariid()        'mencari id
    ds.Clear()
    sql = "select * from USERLIST where USERNAME = '" & LOGIN.USERNAME.Text & "'"
    da.SelectCommand = New OleDbCommand(sql, kns)
    da.Fill(ds, "USERLIST")
End Sub

Sub gantiid()   'mengganti password
    sql = "update USERLIST set USERNAME = '" & LOGIN.USERNAME.Text & "', PASSWORD= '" & renew.Text & "' where USERNAME ='" & LOGIN.USERNAME.Text & "'"
    kns.Open()
    da.UpdateCommand = New OleDbCommand(sql, kns)
    da.UpdateCommand.ExecuteNonQuery()
    kns.Close()
End Sub

Private Sub Ubah_Password_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
    MAIN_MENU.Panel1.Visible = True
End Sub

Private Sub Ubah_Password_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    tampilkan()

    MAIN_MENU.Panel1.Visible = False
End Sub

Private Sub oldpass_TextChanged(sender As Object, e As EventArgs) Handles oldpass.TextChanged
    cariid()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    cariid()

    If ds.Tables("USERLIST").Rows.Count = 0 Then
        MessageBox.Show("You Have Enter Wrong Password", "Warning!")
        oldpass.Clear()
        newpass.Clear()
        renew.Clear()
        oldpass.Focus()
    ElseIf ds.Tables("USERLIST").Rows.Count = 1 And newpass.Text <> renew.Text Then
        MessageBox.Show("New Password And Confirmation Must Be Same!", "Warning!")
        newpass.Clear()
        renew.Clear()
        newpass.Focus()
    ElseIf ds.Tables("USERLIST").Rows.Count = 1 And newpass.Text = renew.Text Then
        gantiid()
        MessageBox.Show("Password Change Is Successful!", "Notice")
        Me.Close()
    End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.Close()
End Sub

末班

链接地址: http://www.djcxy.com/p/42833.html

上一篇: Syntax error in UPDATE statement vb.net in access database

下一篇: Handle database table with null dates using Nullable(Of Date)