Syntax Error in UPDATE statement in VB.net

chemicalee

I have the following query and I can for love nor money work out where the error is in my UPDATE statement? I only started playing with this last week so I'm on a big learning curve!

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    'Declerations For Calling on
    Dim AnimalHouse As String
    AnimalHouse = "TestText"
    Dim AddressForAssingment As Integer
    AddressForAssingment = 1
    Dim IDCheckAssignment As Integer
    IDCheckAssignment = 1
    Dim CommandText As String = _
        "UPDATE IOInformation.Description = @animalHouse, WHERE ID_number = @addrForAssn AND ID_Check = @Id;"

    'Connection Information 
    Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ProjectDirectory.Text)
    Dim myCommand As New OleDbCommand(CommandText)
    myCommand.Parameters.AddWithValue("@animalHouse", AnimalHouse)
    myCommand.Parameters.AddWithValue("@addrForAssn", AddressForAssingment)
    myCommand.Parameters.AddWithValue("@Id", IDCheckAssignment)

    myCommand.Connection = myConnection
    myConnection.Open()
    myCommand.ExecuteNonQuery()
    myConnection.Close()


End Sub
Steve

You have a couple of errors in your syntax.

The correct syntax for an UPDATE query is

UPDATE table SET field1=value1, field2=value2, ...... WHERE keyfield=value

so you should write

Dim CommandText As String = _
    "UPDATE IOInformation SET Description = @animalHouse " & 
    "WHERE ID_number = @addrForAssn AND ID_Check = @Id;"

Separate the table name from the field name, add a SET before the first fieldname and remove the comma before the WHERE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related