I'm trying to determine why I receive this error message when attempting to update the database.."Syntax error in UPDATE statement", please assist!
Thanks!
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim SQLStmt As String
Dim UpdateOK As Integer
If txtFirstName.Text = "" And txtLastName.Text = "" Then
MsgBox("All Account records must have at least a last or first name. Companies' names should be entered in the LastName field, leaving the FirstName field empty...")
txtLastName.Focus()
Return
End If
Dim UpdateCnxn As New OleDbConnection( _
"Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=DB.mdb")
UpdateCnxn.Open()
'escape any quotes to avoid problems with SQL...
txtLoginId.Text.Replace("'", "''")
txtPassword.Text.Replace("'", "''")
txtFirstName.Text.Replace("'", "''")
txtLastName.Text.Replace("'", "''")
If lblId.Text = "New" Then
SQLStmt = String.Format("insert into ACCOUNTS (LoginId, LoginPwd, Primary Role, FirstName, LastName) values ('{0}', '{1}', '{2}', '{3}', '{4}')", _
txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtLastName.Text, txtFirstName.Text)
Else
SQLStmt = String.Format("update ACCOUNTS set LoginId='{0}', LoginPwd='{1}', Primary Role='{2}', FirstName='{3}', LastName='{4}' where Id={5}", _
txtLoginId.Text, txtPassword.Text, cbMenuType.Text, txtFirstName.Text, txtLastName.Text, lblId.Text)
End If
Dim UpdateCommand As New OleDbCommand(SQLStmt, UpdateCnxn)
Debug.Write("UpdateSQLStmt=" & SQLStmt & vbCrLf)
UpdateOK = UpdateCommand.ExecuteNonQuery()
UpdateCnxn.Close()
ClearInputAreas()
txtSearch.Text = ""
lblAdvice.Text = "Enter some characters of the last name, or company name, to search for an Account. Or, enter the Account # if you have it. Click the New button to create a new account record."
txtSearch.Focus()
End Sub