[Solved] INSERT INTO syntax error in c#


This should work:

OleDbCommand cmd = new OleDbCommand(@"INSERT INTO tbbill(invoice,[datetime],custm,total,tax,grand) 
VALUES(" + Convert.ToInt32(txtinvoice.Text) + ",\"" +          
dateTimePicker1.Value.ToString("yyyy/MMM/dd") + "\",\"" + 
Convert.ToString(txtcn.Text) + "\",\"" + txtttl.Text + "\",\"" + 
Convert.ToInt32(cmtax.Text) + "\",\"" + txtgrdttl.Text + "\")", con);
cmd.CommandType = CommandType.Text; 
cmd.ExecuteNonQuery(); 
con.Close();

EDIT:

As stated by others, your query is still open to SQL injection. Dmitry’s answer will be the safest and efficient option.

solved INSERT INTO syntax error in c#