Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What Wrong with this code..



VB
Private Sub useradd_Click()
Dim cmd as New ADODB.Command

cmd.ActiveConnection = con
cmd.CommandText = "insert into userlist(emp_id,first_name,last_name,username,password,usertype) values(" & empid.Text & ",'" & fn.Text & "','" & ln.Text & "','" & un.Text & "','" & pwd.Text & "','" & usertype.Text & "');"
'On Error GoTo errlbl
cmd.Execute
MsgBox "User Created Successfully", vbInformation
Exit Sub
'errlbl:
'MsgBox "Error : " & Err.Number & Err.Description, vbCritical
End Sub



Error Shown INSERT INTO Syntax error
Posted
Comments
F-ES Sitecore 26-Oct-15 4:58am    
The code will fail if any of your text boxes have an apostrophe, or the empid is not numeric. Use parameterised queries instead of building the SQL like that, as your code is prone to sql injection attacks.

1 solution

I would grab the cmd.CommandText value at runtime (using the debugger) and then use such a value to query directly the database engine (in order to better understand what the error is).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900