When I try to insert into my Partial table, I get a syntax error which I cannot solve; I tried everything and it works fine in access query but in c# it doesn't.
My code:
string strcomm = @"Insert Into Partial values(@c_name,@w_name,@ssn,@Product_name,@Price,
@Amount,@Total,@fir,@buy_date,@discount)";
OleDbCommand command = new OleDbCommand(strcomm, connection);
command.Parameters.AddWithValue("@c_name", 1 /*pills_grid.Rows[i].Cells[4].Value*/);
command.Parameters.AddWithValue("@w_name", 1 /*pills_grid.Rows[i].Cells[5].Value*/);
command.Parameters.AddWithValue("@ssn", 1 /*pills_grid.Rows[i].Cells[8].Value*/);
command.Parameters.AddWithValue("@Product_name", 1 /*pills_grid.Rows[i].Cells[0].Value*/);
command.Parameters.AddWithValue("@Price", 1 /*pills_grid.Rows[i].Cells[1].Value*/);
command.Parameters.AddWithValue("@Amount", 1/* pills_grid.Rows[i].Cells[2].Value*/);
command.Parameters.AddWithValue("@Total", 1 /*pills_grid.Rows[i].Cells[3].Value*/);
command.Parameters.AddWithValue("@fir", 1 /*pills_grid.Rows[i].Cells[9].Value*/);
command.Parameters.AddWithValue("@buy_date", "2010-1-1" /*pills_grid.Rows[i].Cells[6].Value*/);
command.Parameters.AddWithValue("@discount", 1 /*pills_grid.Rows[i].Cells[7].Value*/);
command.ExecuteNonQuery();
I use 1's as inputs just to try nothing more
It works perfectly in Access and throws this error in C#:
Syntax error in INSERT INTO statement
INT?AddWithValue.AddWithValue. Doing so is not meant to address this particular issue, but to improve the quality of your code overall. Using that method is generally a bad idea for reasons specified in the link.