命令执行期间更新语句错误

时间:2014-03-25 23:24:52

标签: asp.net vb.net

Dim iReturn As Boolean
    Using SQLConnection As New MySqlConnection(strMySqlConnectionString)
        Using sqlCommand As New MySqlCommand

            With sqlCommand
                .CommandText = "UPDATE user" & "SET FirstName = @FirstName" & "From user" & "WHERE Username = @Username;"
                .Connection = SQLConnection
                .CommandType = CommandType.Text '// You missed this line
                .Parameters.AddWithValue("@FirstName", editFirsName.Text)
                .Parameters.AddWithValue("@Username", editusername.Text)


            End With
            Try
                SQLConnection.Open()
                sqlCommand.ExecuteNonQuery()
                iReturn = True
                MsgBox("User Was Update succesfully")
            Catch ex As MySqlException
                MsgBox(ex.Message.ToString)
                iReturn = False
            Finally
                SQLConnection.Close()
            End Try

        End Using
    End Using

    If iReturn = False Then
    End If

我从上面的代码中收到以下错误:

  

命令执行期间遇到致命错误。

1 个答案:

答案 0 :(得分:0)

您的SQL更新语法显示不正确。

更改:

.CommandText = "UPDATE user" & "SET FirstName = @FirstName" & "From user" & "WHERE Username = @Username;"

.CommandText = "UPDATE user SET FirstName = @FirstName WHERE Username = @Username;"