{ // Get the poll PollInfo poll = PollInfoProvider.GetPollInfo("MyNewPoll");
if (poll != null) { // Create new answer object PollAnswerInfo newAnswer = newPollAnswerInfo();
// Set the properties newAnswer.AnswerPollID = poll.PollID; newAnswer.AnswerText = "My new answer"; newAnswer.AnswerEnabled = true; newAnswer.AnswerCount = 0;
// Save the answer PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);
returntrue; }
returnfalse; }
The following example gets and updates an answer.
privatebool GetAndUpdateAnswer() { // Get the answer PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll");
if (updatePoll != null) { // Get the data DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID); if (!DataHelper.DataSourceIsEmpty(answers)) { // Loop through the individual items foreach (DataRow answerDr in answers.Tables[0].Rows) { // Create object from DataRow PollAnswerInfo modifyAnswer = newPollAnswerInfo(answerDr);
// Update the properties modifyAnswer.AnswerText = modifyAnswer.AnswerText.ToUpper();
// Save the changes PollAnswerInfoProvider.SetPollAnswerInfo(modifyAnswer); }
returntrue; } }
returnfalse; }
The following example deletes an answer.
privatebool DeleteAnswer() { // Get the poll PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll");
if (updatePoll != null) { // Get the answer DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);
if (!DataHelper.DataSourceIsEmpty(answers)) { PollAnswerInfo deleteAnswer = newPollAnswerInfo(answers.Tables[0].Rows[0]);
// Delete the answer PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);