Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Thanked 0 Times in 0 Posts

    Syntax error in UPDATE statement.

    I have this error when I run this code:

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Passwords.accdb"

    Dim SqlString As String = "Update [Pass] Set UserName = ?, Password = ?"

    Using conn As New OleDb.OleDbConnection(ConnString)

    Using cmd As New OleDb.OleDbCommand(SqlString, conn)

    cmd.CommandType = CommandType.Text

    cmd.Parameters.AddWithValue("UserName", TextBox1.Text)

    cmd.Parameters.AddWithValue("Password", TextBox2.Text)



    End Using

    End Using
    End Sub
    End Class

    I am a newbbie in xthis field so I will provide you details of the access database:

    Database name: Passwords.accdb
    Table name: Pass : Table
    Fields in the table name: UserName and Password
    I also uploaded a printscreen with my form

    Any suggestions are very welcomed......
    Thank you!
    Attached Thumbnails Attached Thumbnails Syntax error in UPDATE statement.-form.jpg  

  • #2
    New Coder
    Join Date
    Jul 2011
    Chennai, India
    Thanked 5 Times in 5 Posts
    You didn't given the error which thrown during execution.

    Try this, instead of using parameters, supply the values directly in the query and execute.
    Like this
    Dim SqlString As String = "Update [Pass] Set UserName = '"+TextBox1.Text+"', Password = '" + TextBox2.Text + '"

    Make sure that the both text boxes are not null.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts