Code is running fine, has connected to the database successfully, however I cannot see where the error is in this INSERT query, can anyone see the error?
string SaveUserQuery = "INSERT INTO Employee (PayrollNo, FirstName, LastName, Password, AnnualHolidayEntitlement, DaysTakenToDate, Admin, Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)";
Edit, Added the error.
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement.
Edit, Added how I have added parameters for clarity
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;
答案 0 :(得分:1)
Try this, I think you got some key words that need to be in brackets to tell sql its a field.
INSERT INTO Employee (PayrollNo, FirstName, LastName, [Password], AnnualHolidayEntitlement, DaysTakenToDate, [Admin], Department) Values(@PayrollNo, @FirstName, @LastName, @Password, @AnnualHolidayEntitlement, @DaysTakenToDate, @Admin, @Department)