insertTimestamp=DateTime.UtcNow;try{using(varconnection=newNpgsqlConnection(_connectionString.ConnectionString)){connection.OpenWithRetry();using(varinsertVoteCommand=connection.CreateCommand()){insertVoteCommand.CommandText=@"INSERT INTO votes (candidate, time_cast) VALUES (@candidate, @time_cast)";varcandidate=insertVoteCommand.CreateParameter();candidate.ParameterName="@candidate";candidate.DbType=DbType.String;candidate.Value=team;insertVoteCommand.Parameters.Add(candidate);vartimeCast=insertVoteCommand.CreateParameter();timeCast.ParameterName="@time_cast";timeCast.DbType=DbType.DateTime;timeCast.Value=insertTimestamp;insertVoteCommand.Parameters.Add(timeCast);awaitinsertVoteCommand.ExecuteNonQueryAsync();}}returnContent($"Vote successfully cast for '{team}' at time {insertTimestamp}!");}catch(Exceptionex){// If something goes wrong, handle the error in this// section. This might involve retrying or adjusting// parameters depending on the situation.returnStatusCode((int)HttpStatusCode.InternalServerError,ex);}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[],[]]