0

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

17
  • 3
    It would be helpful to post the error message. Also, is every column you are inserting of type INT? Commented Jul 17, 2018 at 17:00
  • Please explain why it is not working. Commented Jul 17, 2018 at 17:02
  • 2
    Stop using AddWithValue. Commented Jul 17, 2018 at 17:03
  • @DanWilson i don't not it gives syntax error in insert into statement but it works perfectly in ms access query Commented Jul 17, 2018 at 17:03
  • 2
    @MostafaIbrahem You should stop using 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. Commented Jul 17, 2018 at 17:09

1 Answer 1

1

Partial is a reserved word in Access. You should wrap it in square brackets - [Partial].

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

1 Comment

Thank you i kept looking in my parameters for reserved words and missed the table name :]

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.