Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
am tryna make a system and when am trying to save to database , its displaying incorrect syntax error near ',' , please help howdo l solve this

What I have tried:

mmm wanna know wah to try so please help me to solve this
Posted
Updated 29-Dec-21 7:10am
Comments
Patrice T 28-Dec-21 21:52pm    
You have a secret error in your secret code.
Wendelius 29-Dec-21 1:22am    
Please post relevant parts of the code that are causing this error.

We can't tell you: we have no access to your code.
The error message though looks like an error in the SQL Command you are sending to your DB system - so start by looking at that.

And a question this poorly asked implies you are a beginner, so the most lively things are:
1) A missing or extra character in your command string. Start here: SQL Syntax[^] and compare your string against the actual syntax.
2) String concatenation for parameter values. This means doing things like this:
VB
Dim cmd as String = "SELECT * FROM MyTable WHERE ID = " & userId
Or
VB
Dim cmd as String = "INSERT INTO MYTable (UserNm) VALUES ('" & userName & "')"
Both of which use string concatenation to "build" an SQL command.
And that's a major problem: if the variable contains a "'" then it confuses SQL and you get an error. But that's trivial: it also leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
 
Share this answer
 
There can be several causes of such of error. I'd suggest to visit this link: LMGTFY - Let Me Google That For You[^]
We can't help you more due to none information about the code which causes that error.
 
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