Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Home User: Win 7(64 bit) VBExpress 2010: Parsing Error Expand / Collapse
Author
Message
Posted Monday, March 5, 2012 1:21 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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.
Post #1261801
Posted Tuesday, March 6, 2012 7:48 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Thursday, December 18, 2014 8:26 AM
Points: 10,381, Visits: 13,436
I'm going to make a couple of comments.

1. Concatenating text to create a SQL Statement in the application leaves your application vulnerable to SQL Injection. You should search for SQL Injection and code to avoid it.
2. In your UPDATE statement you need to do "SET column = " and I don't see any "=" signs in the UPDATE.
3. You also need to make sure you are wrapping string values in single-quotes so your code should be like this:
SQL = "Update table SET column = '" & control.Text & "' WHERE ID=" & IDControl.Text

I'm assuming the ID column is a numeric column.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #1262205
Posted Tuesday, March 6, 2012 8:18 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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.
Post #1262239
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse