1

This is my code:

Dim job As String = TextBoxJobNum.Text
    Dim idws As Integer

sqlQuery = "UDATE Equipment SET JobHistory = JobHistory+'" & job & "' WHERE ID = '" & idws & "'"

        Dim sqlCmd1 As New SqlCommand(sqlQuery, sqlConn)

        If sqlConn.State = ConnectionState.Closed Then sqlConn.Open()
        For Each row As DataGridViewRow In DataGridViewEquip.Rows
            idws = CInt(row.Cells(0).Value)
            sqlCmd1.ExecuteNonQuery()
        Next
        If sqlConn.State = ConnectionState.Open Then sqlConn.Close() 

I get the error "Syntax error near '=' " I have searched everywhere but cant seem to find the correct Syntax for this line. Any help would be greatly appreciated.

Simeon
  • 74
  • 6

1 Answers1

1

Looks to me like you are just missing a "P" in the word "UPDATE"

sqlQuery = "UPDATE Equipment SET JobHistory = JobHistory+'" & job & "' WHERE ID = '" & idws & "'"

Also I would recommend not setting parameters using string concatenation, but instead use parameters on a SqlCommand object. The reason for this is reducing potential problems such as additional escaping (if the "job" variable contains a "'" for example) or SQL injection.

Community
  • 1
  • 1
  • Thanks will look at the link. Cant believe i missed the P lol. The code runs without error, but the column data does net get update. But I guess that is because of something else. Will see if I cant find the problem. Just to be sure, the syntax for adding new values to current values is correct? – Simeon Nov 13 '13 at 08:53
  • This part: JobHistory+'" & job & "' – Simeon Nov 13 '13 at 08:54
  • Well, that actually concatenated the new value in the "job" variable to the existing value in the "JobHistory" field in the database. Don't know if that's what you are trying to do. If you really want to update it to the value from the "job" variable you should drop the "JobHistory+" part. – Wouter van der Neut Nov 13 '13 at 08:57
  • Yes I want to concatenate the new value to the existing one – Simeon Nov 13 '13 at 09:03