插入到语句中的sql查询和c#中的错误

问题描述 投票:0回答:1

当我尝试插入我的Partial表时,我得到一个语法错误,我无法解决;我尝试了一切,它在访问查询中工作正常,但在c#中却没有。

我的代码:

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();

我使用1作为输入只是为了尝试更多

它在Access中完美运行并在C#中抛出此错误:

INSERT INTO语句中的语法错误

c# sql ms-access
1个回答
1
投票

Partial是Access中的保留字。你应该把它包在方括号中 - [Partial]

© www.soinside.com 2019 - 2024. All rights reserved.