I am fairly new to SQL in Pascal and Lazarus and I have a problem in my code. I'm using a form-based application and I'm trying to update one of my tables in my database so that Employees can be given points by their managers. So a bit of background, A manager logs in with a Username and password then in a box they will type the employee ID and then type the amount of points they award and then press submit. When I try this it says Debugger error:The GDB command: "x/s Exception($rcx).FMessage" did not return any result." and project test raised exception class 'EDatabaseerror'. Here Is my procedure:
procedure TManager.AwardSubmitButtonClick(Sender: TObject);
sqlquery1.close;
sqlquery1.sql.text:='UPDATE Employee SET Points= :ENTEREDPOINTS WHERE EmployeeID= :ENTEREDID';
sqlquery1.params.parambyname('ENTEREDPOINTS').AsInteger:=StrtoInt(PointEditBox.text);
sqlquery1.params.parambyname('ENTEREDID').AsInteger:=StrtoInt(EmployeeIDEditBox.text);
sqlquery1.open;
I have tried to put manager.sqlquery1 etc which is the name of the form but that doesn't help. Also I've tried a Join statement but I've probably done that wrong because I haven't tried it before. What I really want to do is ensure that the manager who currently looks at its seven employees that it is connected to by a foreign key 'ManagerID', can update the points of its seven employees and its seven employees only. I have used a multi-table query to ensure only the seven employees the manager is associated to is displayed when they log in. My code for this is here:
foundM:=false;
sqlquery1.close;
sqlquery1.sql.text:='Select Username,Password FROM Manager';
sqlquery1.open;
While not (sqlquery1.eof) AND (foundM=false) do
begin
If (UsernameEditBox.text=sqlquery1.fields[0].AsString) AND (PasswordEditBox.text=sqlquery1.fields[1].AsString) then
begin
Manager.show;
Manager.sqlquery1.close;
Manager.sqlquery1.sql.text:='Select Employee.EmployeeID,Employee.Firstname,Employee.Surname,Employee.Points,Employee.Target,Employee.comment,Employee.EOYRating,Employee.Appointment,Employee.ApprovedPoints,Employee.ManagerID FROM Employee,Manager WHERE Employee.ManagerID=Manager.ManagerID AND Manager.Username= :Manager';
Manager.sqlquery1.params.parambyname('Manager').AsString:=Main.UsernameEditbox.text;
Manager.sqlquery1.open;
foundM:=true;
end
else
sqlquery1.next;
end;
sqlquery1.close;
If someone is able to help me solve my first problem of ensuring the first piece of code works then possibly showing me how I would adapt it so that the manager could only update its employees that its linked to by the foreign key 'ManagerID' then that would be incredibly helpful.
I hope this is enough information, if it isn't then feel free to say what information you would like. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire