1

这是我的代码:

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() 

我收到错误“'=' 附近的语法错误”我到处搜索,但似乎找不到该行的正确语法。任何帮助将不胜感激。

4

1 回答 1

1

在我看来,您只是在“更新”一词中缺少一个“P”

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

另外我建议不要使用字符串连接设置参数,而是在 SqlCommand 对象上使用参数。这样做的原因是减少了潜在的问题,例如额外的转义(例如,如果“job”变量包含“'”)或 SQL 注入。

于 2013-11-13T08:43:00.713 回答