INSERT INTO 查询出错
Error in INSERT INTO query
代码 运行 没问题,已成功连接到数据库,但是我看不出这个 INSERT 查询中的错误在哪里,任何人都可以看到错误吗?
string SaveUserQuery = "INSERT INTO Employee (PayrollNo, FirstName, LastName, Password, AnnualHolidayEntitlement, DaysTakenToDate, Admin, Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)";
编辑,添加错误。
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
编辑,为清楚起见添加了我添加参数的方式
SaveUser.Parameters.AddWithValue("@PayrollNo", OleDbType.VarChar).Value = Convert.ToInt32(txtPayrollNo.Text);
SaveUser.Parameters.AddWithValue("@FirstName", OleDbType.VarChar).Value = txtFirstName.Text;
SaveUser.Parameters.AddWithValue("@LastName", OleDbType.VarChar).Value = txtLastName.Text;
SaveUser.Parameters.AddWithValue("@Password", OleDbType.VarChar).Value = "12345";
SaveUser.Parameters.AddWithValue("@AnnualHolidayEntitlement", OleDbType.VarChar).Value = Convert.ToInt32(TxtAHE.Text);
SaveUser.Parameters.AddWithValue("@DaysTakenToDate", OleDbType.VarChar).Value = Convert.ToInt32(TxtDTTD.Text);
if (IsAdmin()) { SaveUser.Parameters.AddWithValue("@Admin", OleDbType.VarChar).Value = "Y"; }
else { SaveUser.Parameters.AddWithValue("@Admin", OleDbType.VarChar).Value = "N"; }
SaveUser.Parameters.AddWithValue("@Department", OleDbType.VarChar).Value = cbbDepartment.Text;
试试这个,我想你得到了一些需要放在括号中的关键字来告诉 sql 它是一个字段。
INSERT INTO Employee (PayrollNo, FirstName, LastName, [Password], AnnualHolidayEntitlement, DaysTakenToDate, [Admin], Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)
代码 运行 没问题,已成功连接到数据库,但是我看不出这个 INSERT 查询中的错误在哪里,任何人都可以看到错误吗?
string SaveUserQuery = "INSERT INTO Employee (PayrollNo, FirstName, LastName, Password, AnnualHolidayEntitlement, DaysTakenToDate, Admin, Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)";
编辑,添加错误。
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
编辑,为清楚起见添加了我添加参数的方式
SaveUser.Parameters.AddWithValue("@PayrollNo", OleDbType.VarChar).Value = Convert.ToInt32(txtPayrollNo.Text);
SaveUser.Parameters.AddWithValue("@FirstName", OleDbType.VarChar).Value = txtFirstName.Text;
SaveUser.Parameters.AddWithValue("@LastName", OleDbType.VarChar).Value = txtLastName.Text;
SaveUser.Parameters.AddWithValue("@Password", OleDbType.VarChar).Value = "12345";
SaveUser.Parameters.AddWithValue("@AnnualHolidayEntitlement", OleDbType.VarChar).Value = Convert.ToInt32(TxtAHE.Text);
SaveUser.Parameters.AddWithValue("@DaysTakenToDate", OleDbType.VarChar).Value = Convert.ToInt32(TxtDTTD.Text);
if (IsAdmin()) { SaveUser.Parameters.AddWithValue("@Admin", OleDbType.VarChar).Value = "Y"; }
else { SaveUser.Parameters.AddWithValue("@Admin", OleDbType.VarChar).Value = "N"; }
SaveUser.Parameters.AddWithValue("@Department", OleDbType.VarChar).Value = cbbDepartment.Text;
试试这个,我想你得到了一些需要放在括号中的关键字来告诉 sql 它是一个字段。
INSERT INTO Employee (PayrollNo, FirstName, LastName, [Password], AnnualHolidayEntitlement, DaysTakenToDate, [Admin], Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)