Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This my count code to display error if the data is already exists in database
C++
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM tbl_register WHERE ([Email_Id] = @Email_Id)", con);

AND the ERROR is showing like this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Email_Id] = @Email_Id)' at line 1

What I have tried:

I have tried like clause.
this is done by adding parameters
Posted
Updated 23-Aug-17 23:26pm
Comments
Graeme_Grant 24-Aug-17 2:53am    
@Email_Id is expecting a parameter before execution. Are you passing one? Where is the rest of the calling code?
Simon_Whale 24-Aug-17 3:32am    
have you tried to run the query directly in MySql?

1 solution

You use MySQL, not Microsoft SQL Server. Consequently, those square brackets cannot be used for escaping field names. In MySQL, you use backticks ` instead. But anyway, you do not need to escape the field name here, it is not a reserved word nor does it contain spaces.
MySqlCommand cmd = new MySqlCommand("SELECT COUNT(*) FROM tbl_register WHERE (Email_Id = @Email_Id)", con);
Also, make sure you have an index on Email_Id.
 
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