Click here to Skip to main content
14,608,080 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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 !).
   
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!!
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
string sql = "INSERT INTO [transaction] (Dea_Cust_id, total, tax) VALUES (@Dea_Cust_id, @total, @tax)";
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100