|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Sunday, May 13, 2012 5:31 AM
Points: 18,
Visits: 64
|
|
The following error is reported when I attempt to edit a record and then click on save to save the changes:
There was an error parsing the query. [Token line number = 1, Token line ofset = 38, Token in error = /]
This is the button Save code:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Select Case state Case "n" If txtFName.Text = "" Then MsgBox("Name Cannot be null", , "My Telephone Book") Else Try Using conn = New SqlCeConnection(connString) Using cmd = New SqlCeCommand cmd.Connection = conn cmd.CommandText = "INSERT INTO Persons (" & _ "Fullname, " & "DoB, " & "DoM, " & "MPhone, " & "EMail, " & "Notes, " & "AddressID) " & "VALUES " & "(?,?,?,?,?,?,?)" With cmd.Parameters.Add("FullName", Me.txtFName.Text) cmd.Parameters.Add("DoB", Me.dtpDoB.Value) cmd.Parameters.Add("Dom", Me.dtpDoM.Value) cmd.Parameters.Add("MPhone", Me.txtMPhone.Text) cmd.Parameters.Add("EMail", Me.txtEMail.Text) cmd.Parameters.Add("Notes", Me.txtNotes.Text) cmd.Parameters.Add("AddressID", Me.txtAddressID.Text) End With conn.Open() cmd.ExecuteNonQuery() End Using End Using MsgBox("Record Saved", , "My Telephone Book") Catch sqlex As SqlCeException Dim sqlError As SqlCeError For Each sqlError In sqlex.Errors MessageBox.Show(sqlError.Message) Next Catch ex As Exception MsgBox("Error Saving Record", , "My Telephone Book") Finally conn.Close() End Try End If
Case "u" If txtFName.Text = "" Then MsgBox("Full Name cannot be empty", "My Telephone Book") Else Try conn.Open() Dim cmd As SqlCeCommand = conn.CreateCommand 'This is I believe is the Error line below cmd.CommandText = "UPDATE Persons SET FullName" & txtFName.Text & "DoB" & dtpDoB.Value & "DoM" & dtpDoM.Value & "MPhone" & txtMPhone.Text & "EMail" & txtEMail.Text & "Notes" & txtNotes.Text & "FROM Persons WHERE PersonID = " & lstPersonID.Text cmd.ExecuteNonQuery() MsgBox("Record Updated", , "My Telephone Book") conn.Close() Call FillList() Catch sqlex As SqlCeException Dim sqlError As SqlCeError For Each sqlError In sqlex.Errors MessageBox.Show(sqlError.Message) Next Catch ex As Exception 'MsgBox("Error Updating Record", , "My Telephone Book") MessageBox.Show(ex.Message) Finally conn.Close() End Try End If End Select sql = "SELECT * FROM Persons ORDER BY FullName" Call FillList() txtFind.Clear() txtFName.Focus() End Sub
Any help will be greatly appreciated as i've spent all day attempting to resolve this error.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571,
Visits: 11,871
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Sunday, May 13, 2012 5:31 AM
Points: 18,
Visits: 64
|
|
| T.hank you kindly for your response, Yes, the "ID" field is numeric. I will read up on SQL Injection.
|
|
|
|