Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what could be possible syntax error in this ..



q1 = "UPDATE clients SET name='" & txtname.Text & "',add='" & txtadd.Text & "',contact='" & txtco.Text & "',email='" & txtemail.Text & "',bal=" & txtbal.Text & "where ID=" & cid & ";"


this command is showing as syntax error... :(

please help..
Posted

Would you like a list?

Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead. It also frequently causes problems like this.

What is the content of your textboxes? Since you are handing it to SQL as part of a string, it is very relevant when tryingf to diagnose a problem.
VB
q1 = "UPDATE clients SET name=@NAME,add=@ADD,contact=@CONT,email=@EMAIL,bal=@BAL WHERE ID=@ID"

Then hand the parameters to your SqlCommand object:
VB
cmd.Parameters.AddWithVAlue("@NAME", txtname.Text)
cmd.Parameters.AddWithVAlue("@ADD", txtadd.Text)
cmd.Parameters.AddWithVAlue("@CONT", txtco.Text)
cmd.Parameters.AddWithVAlue("@EMAIL", txtemail.Text)
cmd.Parameters.AddWithVAlue("@BAL", txtbal.Text)
cmd.Parameters.AddWithVAlue("@ID", cid)
 
Share this answer
 
Hi cool aashi143,

your error is near
VB
bal= txtbal.Text 

change it to
VB
bal= cint(txtbal.Text)


Reason is when you send values to database the field with numeric values must be converted to Number/ Integer. Here CInt converts the value in the txtbal Textbox to integer as it was in String as everything in textbox is considered as String.



Thanks,
 
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