Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
tryin to enter transaction details to a table. when clicking the save button i get this error message;
Incorrect syntax near the keyword 'transaction'.

What I have tried:

i checked the code thoroughly but i cant seem to fing any syntax error.

string sql = "INSERT INTO transaction (Dea_Cust_id, total, tax) VALUES (@Dea_Cust_id, @total, @tax)";


above is the bit of code that seems to be the problem. can u point out any possible mistakes?
Posted
Updated 29-Jul-20 3:06am

Transaction may be a key word in your database server.

Try (1) surrounding it with appropriate delimters ([] in MS-SQL) or try a different name for your table.

(you wouldn't name a table "WHERE" "SELECT", "DELETE" or "TRUNCATE", I hope !).
 
Share this answer
 
v2
Comments
CHill60 29-Jul-20 9:07am    
Snap :)
achalake 29-Jul-20 22:46pm    
@W∴ Balboos, GHB thank u for ur suggestion. it worked!!
It's because you have used a reserved word as a table name - see Reserved Keywords (Transact-SQL) - SQL Server | Microsoft Docs[^]
Try surrounding the table name with [ ] i.e.
C#
string sql = "INSERT INTO [transaction] (Dea_Cust_id, total, tax) VALUES (@Dea_Cust_id, @total, @tax)";
 
Share this answer
 
Comments
Patrice T 29-Jul-20 9:41am    
+5
achalake 29-Jul-20 22:42pm    
@CHill60 thank u so much. i tried what u suggested and it worked. thanks again

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