0

I have an error in my SQL statement. This is the query:

 MySqlCommand cmd = new MySqlCommand("insert into bills (bill_Number,bill_Date,bill_From,bill_Note,bill_TaxRate,bill_DisRate,bill_EntryDate,cus_Sup,by,archived) values(" + txbBillNumber.Text + ",'" + DateTime.Parse(txbBillDate.Text).Year + "-" + DateTime.Parse(txbBillDate.Text).Month + "-" + DateTime.Parse(txbBillDate.Text).Day + "'," + sup_Id + ",'" + txb_Note.Text + "'," + taxRate + "," + disRate + ",'" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "'," + Bills.cus_Sup + ",0,0)", objConn);
                        cmd.ExecuteNonQuery();

And in this image the error and the bills table structure: Screebshot1

0

3 Answers 3

4

One problem is that the word by that you use as a column is a reserved keyword (both in MySQL and the SQL standard in general). To use it you have to enclose it in backticks `` or double-quotes " ".

Also, the string values need to be between single-quotes where applicable, but I think you got that.

On a side note you should look into using parametrized queries instead of concatenating. See this question for an example: C# with MySQL INSERT parameters

Sign up to request clarification or add additional context in comments.

Comments

1

Your string values must be enclosed in quotes in the SQL statement, like this: MySqlCommand cmd = new MySqlCommand("insert into bills (bill_Number,bill_Date,bill_From,bill_Note,bill_TaxRate,bill_DisRate,bill_EntryDate,cus_Sup,by,archived) values(\"" + txbBillNumber.Text + "\"...

Comments

0

My first thoughts is that "by" is a reserved word, and "by" needs to be encapsulated in single/double quotes...whatever mysql requires. This is from sql server experience.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.