Question

Here's my relational database (.accdb):

(sorry, not enough reputation, can't post image)

https://docs.google.com/file/d/0B11KxyqILxOoVFR5OFBBbEplS0k

Code with error:

cmd3.CommandText = "INSERT INTO Transaction ([InvoiceNum], [ItemID], [Quantity]) " +
                     "Values (?, ?, ?)";

cmd3.Parameters.AddWithValue("@InvoiceNum", invoiceNumber);
cmd3.Parameters.AddWithValue("@ItemID", itemID);
cmd3.Parameters.AddWithValue("@Quantity", item.GetQuantity());

cmd3.ExecuteNonQuery(); //ERROR: Syntax error in INSERT INTO statement

If I INSERT INTO Transaction2 instead, it works.

Working code:

 cmd3.CommandText = "INSERT INTO Transaction2 ([InvoiceNum], [ItemID], [Quantity]) " +
                     "Values (?, ?, ?)";

cmd3.Parameters.AddWithValue("@InvoiceNum", invoiceNumber);
cmd3.Parameters.AddWithValue("@ItemID", itemID);
cmd3.Parameters.AddWithValue("@Quantity", item.GetQuantity());

cmd3.ExecuteNonQuery(); 

I think the problem has something to do with 'Transaction' having relationships with 'Invoice' and 'Item'.

Please Help!

Was it helpful?

Solution

The word TRANSACTION is a reserved word in SQL. Use a different name for your table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top