更新语句vb.net中的语法错误

时间:2013-09-23 03:24:34

标签: vb.net

我在更新时遇到错误。我对这段代码不熟悉。我真的很感激任何帮助。

 Private Sub Save_Record()
    Dim conn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim sSQL As String = "SELECT * FROM Instructor"
    Try
        'get connection string declared in the Module1.vb and assing it to conn variable
        conn = New OleDbConnection(Get_Constring)
        conn.Open()
        cmd.Connection = conn
        cmd.CommandType = CommandType.Text
        'I just use the textbox tag property to idetify if the data is new or existing.

        sSQL = "UPDATE Instructor set fname =  ?, lname =?, mname =? , [password] = ?, [level]=?, where Username = ?"
        cmd.CommandText = sSQL
        cmd.Parameters.AddWithValue("@p1", txtfname.Text)
        cmd.Parameters.AddWithValue("@p2", txtlname.Text)
        cmd.Parameters.AddWithValue("@p3", txtinitial.Text)
        cmd.Parameters.AddWithValue("@p4", txtpass.Text)
        cmd.Parameters.AddWithValue("@p5", lbllevel.Text)
        cmd.Parameters.AddWithValue("@p6", txtusername.Text)
        cmd.ExecuteNonQuery()
        MsgBox("Data has been save.")
    Catch ex As Exception
        MsgBox(ErrorToString)
    Finally
        conn.Close()
    End Try
End Sub

1 个答案:

答案 0 :(得分:2)

你在[level]=?, where Username之前有一个额外的昏迷。试试这个

sSQL = "UPDATE Instructor set fname =  ?, lname =?, mname =? , [password] = ?, [level]=? where Username = ?"