When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Saturday, July 10, 1999

Creating User Polls, Part 3

  • Read Part 1 of Creating User Polls
  • Read Part 2 of Creating User Polls

    - continued -

    The time has come where we need to update our database. This is done in the file pollResults.asp. You may have noticed that this was the file specified in the FORM's ACTION tag. So, let's ask ourselves, "What does pollResults.asp need to do?" The answer is simple: increment the Votes column for the correct PollOption. We have all the information we need from the previous page, so let's get to it.

    <%@ Language=VBScript %>
    <% Option Explicit %>
    Response.ExpiresAbsolute = Now() - 1

    'All we want to do here is increment the vote count for
    ' the voting option selected...

    Dim objConn
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & _
         Server.MapPath("Poll.mdb") & ";"

    'Read in our PollOptionID variable
    Dim iPollOptionID
    iPollOptionID = CInt(Request("radPoll"))

    objConn.Execute "UPDATE PollOption SET Votes = Votes + 1 " & _
          "WHERE PollOptionID = " & iPollOptionID

    'Clean Up...
    Set objConn = Nothing
    'We've gotta write a cookie
    Response.Cookies("Voted") = "Yes"
    Response.Cookies("Voted").Expires = DateAdd("d",1,Date)

    'Send the user back to the previous page
    Response.Redirect Request("URLFrom")

    That's all there is to it. Pretty simple, eh? We just update the PollOption table, incrementing the Votes column by one. We then set a cookie to indicate that this user has voted (the cookie is set to expire tomorrow... you can extend this if you like...), and we redirect them back to the page we came from!

    The Dreaded "Operation must use an updateable query" Error
    A number of users have informed me that when trying to run this script they are receiving Operation must use an updateable query error messages. This is usually due to permission settings on the folder the Access database resides in. Check out the Why am I getting "Operation must use an updateable query" errors? FAQ on ASPFAQs.com for more information.

    We've only got one part left to this system, and that is displaying the results! The code that displays the results exists within the same file as the code that shows the voting options. I know it doesn't seem like that, but that's because I wanted to show you just the voting aspect first. For a clearer understanding, you'll want to look through the code, which is available in full at the end of this article...

    So, let's go on to Step 4!

  • Read Part 1 of Creating User Polls
  • Read Part 2 of Creating User Polls
  • Read Part 4 of Creating User Polls

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article