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 関数はデバッグ目的であり、削除されます。