I'm new and this is my first question.
I'm trying to insert a value into the database and I get the error message
Incorrect syntax near ')'.
and cmd.ExecuteNonQuery() gets highlighted. Here's my code:
con.Open()
cmd = New SqlCommand("INSERT INTO orders ('" + IDProduct.Text + "')", con)
cmd.ExecuteNonQuery()
con.Close()
Firstly, NEVER, NEVER NEVER build sql queries like this. Use parameterized queries instead.
Secondly, you're missing "VALUES" in your sql command.
INSERT INTO orders VALUES ( .... )
edit:
Thirdly, as marc_s suggests, it's a good idea to specify column names as well. That way you can avoid some surprises later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With