2013-09-23 65 views
0

我在更新時遇到錯誤。我只是這個代碼的新手。我真的很感激任何幫助。更新語句中的語法錯誤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 
+0

你得到的錯誤信息是什麼? – bansi

+0

更新語句中的語法錯誤 – user2715202

回答

2

你有一個額外的昏迷之前[level]=?, where Username。試試這個

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

呵呵,哇謝謝逗逗...真的很感謝,我會再問更多:) – user2715202