我一直在努力讓這個過程在過去的5個小時內工作。我已經嘗試將它修剪下來,直到它能夠工作並在此基礎上建立起來,但仍然沒有結束。我非常感謝一些幫助,因爲我必須在明天上午以工作狀態介紹這個項目。德爾福的SQL更新過程沒有更新
我修剪了我的代碼(因爲它很長),但問題仍然很明顯。
sqlCon.Connected := true; //TSQLConnection
sqlUsers.Active := true; //TSQLTable
sqlGames.Active := true; //TSQLTable
sqlPredictions.Active := true; //TSQLTable
sqlUsers.First;
//All following variables are integers.
rugbyChampionshipScore := 10;
rugbyChampionshipGamesPredicted:= 10;
rugbyChampionshipGamesCorrect:= 10;
rugbyChampionshipGamesAlmost:= 10;
rugbyChampionshipGamesWrong:= 10;
currieCupScore := 10;
currieCupGamesPredicted := 10;
currieCupGamesCorrect := 10;
currieCupGamesAlmost := 10;
currieCupGamesWrong := 10;
sqlQueryUpdate.Close; //TSQLQuery
sqlQueryUpdate.CommandText := 'UPDATE users SET overallScore=:parScore, overallGamesPredicted=:parGamesPredicted, overallGamesCorrect=:parGamesCorrect, overallGamesAlmost=:parGamesAlmost, overallGamesWrong=:parGamesWrong, overallAccuracy=:parAccuracy WHERE username=:parUsername';
sqlQueryUpdate.Params.Clear;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parUsername', ptUnknown).AsString := sqlUsers.FieldByName('username').AsString;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parScore', ptUnknown).AsInteger := Round((rugbyChampionshipScore + currieCupScore)/(rugbyChampionshipGamesPredicted + currieCupGamesPredicted));
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesPredicted', ptUnknown).AsInteger := rugbyChampionshipGamesPredicted + currieCupGamesPredicted;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesCorrect', ptUnknown).AsInteger := rugbyChampionshipGamesCorrect + currieCupGamesCorrect;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesAlmost', ptUnknown).AsInteger := rugbyChampionshipGamesAlmost + currieCupGamesAlmost;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parGamesWrong', ptUnknown).AsInteger := rugbyChampionshipGamesWrong + currieCupGamesWrong;
sqlQueryUpdate.Params.CreateParam(ftUnknown, 'parAccuracy', ptUnknown).AsInteger := Round(100/(rugbyChampionshipGamesPredicted + currieCupGamesPredicted)*(rugbyChampionshipGamesCorrect + currieCupGamesCorrect) + ((rugbyChampionshipGamesAlmost + currieCupGamesAlmost)/2));
sqlQueryUpdate.ExecSQL();
sqlQueryUpdate.Close;
sqlUsers.Active := false;
sqlGames.Active := false;
sqlPredictions.Active := false;
什麼是'sqlQueryUpdate'?它是否將'CommandType'設置爲'ctQuery'? – TLama
謝謝你的回覆。 'sqlQueryUpdate'是一個'TSQLQuery'組件,我找不到'CommandType'屬性。 – Laz
那麼,首先使用['SQL'](http://docwiki.embarcadero.com/Libraries/XE3/en/Data.SqlExpr.TSQLQuery.SQL)屬性而不是'CommandText'來指定查詢。 – TLama