我使用 Microsoft Jet 引擎和 Microsoft Access (*.mdb) 数据库的应用程序在 Delphi 7 中不断出现错误。我正在通过 TADOQuery 组件进行连接。错误说“参数 iPointsNew 没有默认值”,并且仅在更新/插入查询中使用整数变量时发生:
frmHome.adoqryInLoop.SQL.Text := 'UPDATE Users SET Points = iPointsNew WHERE UID = "'+sUID+'"';
事件处理程序的代码如下:
procedure TfrmAdmin.bmbSubmitClick(Sender: TObject);
var
sScore, sEID, sPrediction, sUID : String;
iRecordCount, x, iPos, iLength, iActual, iPoints, iPointsNew : Integer;
rPrediction : Real;
begin
// Assign values to variables
sScore := IntToStr(sedSuthies.Value) + '-' + IntToStr(sedOpponent.Value);
iActual := sedSuthies.Value + sedOpponent.Value;
sEID := frmHome.arrEID[lstEvents.ItemIndex];
// Update the score for the event in the database
frmHome.adoqryMain.Active := False;
frmHome.adoqryMain.SQL.Clear;
frmHome.adoqryMain.SQL.Text := 'UPDATE Events SET Score = "'+sScore+'",Complete = True WHERE EID = "'+sEID+'" ';
frmHome.adoqryMain.ExecSQL;
frmHome.adoqryMain.SQL.Text := 'SELECT * FROM Predictions WHERE EID = "'+sEID+'" ';
frmHome.adoqryMain.Open;
iRecordCount := frmHome.adoqryMain.RecordCount;
//Assign points to users for all the predictions
for x := 0 to (iRecordCount - 1) do begin
sUID := frmHome.adoqryMain.Fields[1].AsString;
sPrediction := frmHome.adoqryMain.Fields[4].AsString;
iPos := Pos('-',sPrediction) - 1;
iLength := Length(sPrediction) - iPos;
ShowMessage('1');
if ((sedSuthies.Value >= sedOpponent.Value) AND (StrToFloat(Copy(sPrediction, 1, iPos)) >= StrToFloat(Copy(sPrediction, iPos + 2, iLength + 1)))) OR ((sedSuthies.Value < sedOpponent.Value) AND (StrToFloat(Copy(sPrediction, 1, iPos)) < StrToFloat(Copy(sPrediction, iPos + 2, iLength + 1)))) then begin
rPrediction := StrToFloat(Copy(sPrediction, iPos + 2, iLength + 1)) + StrToFloat(Copy(sPrediction, 1, iPos));
if rPrediction >= iActual then
rPrediction := rPrediction - iActual
else
rPrediction := iActual - rPrediction;
iPoints := Round(10 * (1 - (rPrediction / iActual)));
end
else
iPoints := 0;
ShowMessage('2');
frmHome.adoqryInLoop.Close;
frmHome.adoqryInLoop.SQL.Text := 'SELECT * FROM Users WHERE UID ="'+sUID+'"';
frmHome.adoqryInLoop.Open;
iPointsNew := frmHome.adoqryInLoop.Fields[10].AsInteger + iPoints;
ShowMessage(IntToStr(iPointsNew));
frmHome.adoqryInLoop.Close;
frmHome.adoqryInLoop.SQL.Text := 'UPDATE Users SET Points = iPointsNew WHERE UID = "'+sUID+'"';
frmHome.adoqryInLoop.ExecSQL;
frmHome.adoqryInLoop.Close;
frmHome.adoqryInLoop.SQL.Text := 'UPDATE Predictions SET Complete = True WHERE UID = "'+sUID+'" AND EID = "'+sEID+'" ';
frmHome.adoqryInLoop.ExecSQL;
ShowMessage('3');
ShowMessage(IntToStr(iPoints));
frmHome.adoqryMain.Next;
end;
ShowMessage('Score succefully submitted!');
frmHome.UpdateEventLists;
end;
此错误仅在尝试使用整数变量时发生。我尝试了许多解决方案,例如使用引号、加号,甚至使用诸如 10 之类的普通整数进行测试(它在使用设定数字时有效)。任何帮助将不胜感激。
PS ShowMessage 函数用于调试目的,将被删除。