?
Solved

voting poll

Posted on 2009-07-16
7
Medium Priority
?
298 Views
Last Modified: 2012-05-07
I have a poll when I test it. no matter what option I select it always votes value 1. not sure whats wrong. and when I add the cookie to record the vote it does not vote at all.  But for now I just need to know why it only votes for value one.


stored procedure

       (
       @Pk_OptionId  INT
       )
 
AS
--     GETS THE CURRENT NUMBER OF VOTES FOR THAT OPTION
       DECLARE      @i_NumberOfVoteS INT
       
       SELECT @i_NumberOfVotes = Votes
       FROM   PollOptions
       WHERE  PK_OptionId = @Pk_OptionId
 
       UPDATE PollOptions
       SET           Votes = (@i_NumberOfVotes + 1)
       WHERE  PK_OptionId = @Pk_OptionId
 
       RETURN



Protected Sub btnVote_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVote.Click
        RecordVote()
 
        'If Response.Cookies("Voted") Is Nothing Then
        '    Response.Cookies("Voted").Value = "Voted"
        '    Response.Cookies("Voted").Expires = DateTime.Now.AddDays(1)
 
        '    lblError.Visible = False
 
        '    '   Checks if the user can still vote by using cookie
        '    RecordVote()
        'Else
        '    lblError.Visible = True
        'End If
        'Response.Write(Response.Cookies("Voted"))
        '' Response.Redirect("test.aspx")
    End Sub
 
    Private Sub RecordVote()
        Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("Conn").ToString()
        Dim sqlConn As New SqlConnection(strConnString)
 
        sqlConn.Open()
        Dim sqlCmd As New SqlCommand()
 
        sqlCmd.CommandText = "IncrementVote"
        sqlCmd.CommandType = Data.CommandType.StoredProcedure
        sqlCmd.Connection = sqlConn
 
        '   Creation parameters
        Dim sqlParamQuestion As New SqlParameter("@PK_OptionId", Data.SqlDbType.Int)
 
        sqlParamQuestion.Value = rdoPollOptionList.SelectedValue
 
        sqlCmd.Parameters.Add(sqlParamQuestion)
 
        '   Execute stored procedure
        sqlCmd.ExecuteNonQuery()
 
        '   Close connection
        sqlConn.Close()
    End Sub
0
Comment
Question by:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24870255
Here are troubleshooting options:
1: Execute your StoredProc directly from SqlServer and see if it is working as desired.
2: set breakpoint at line:
------> sqlParamQuestion.Value = rdoPollOptionList.SelectedValue
Confirm the "rdoPollOptionList.SelectedValue" has desired value.

Post your observations.
Now a question: How is your rdoPollOptionList DataBound? i.e. dynamically in code-behind?
If so post that code....make sure that you DataBind it once only i.e. Not Page.IsPostBack.
0
 
LVL 9

Author Comment

by:Seven price
ID: 24870471
I excuted the stored procedure that works great.

I used
  If Page.IsPostBack Then
            ' RecordVote()
            Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("Conn").ToString()
            Dim sqlConn As New SqlConnection(strConnString)

            sqlConn.Open()
            Dim sqlCmd As New SqlCommand()

            sqlCmd.CommandText = "IncrementVote"
            sqlCmd.CommandType = Data.CommandType.StoredProcedure
            sqlCmd.Connection = sqlConn

            '   Creation parameters
            Dim sqlParamQuestion As New SqlParameter("@PK_OptionId", Data.SqlDbType.Int)

            sqlParamQuestion.Value = rdoPollOptionList.SelectedValue

            sqlCmd.Parameters.Add(sqlParamQuestion)

            '   Execute stored procedure
            sqlCmd.ExecuteNonQuery()

            '   Close connection
            sqlConn.Close()

instead of not Page.ispostback because the other way did not execute.

But it only finds Value 1 not value 2, 3 ect.



0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24870537
yes but how is your rdoPollOptionList getting its values?
Anythingin your Page_Load method?
Also you misunderstood ...i did NOT mean to put your StoredProc call into IsPostback....that call is fine....
What I am asking is about your RadioButtonList....how is it getting the option values?
Can you share all code related to your RBL
0
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
LVL 9

Author Comment

by:Seven price
ID: 24870542
Private Sub DisplayPoll()
        Try
            Dim ds As DataSet = getActivePoll()

            '   Displays the poll
            lblPollQuestion.Text = ds.Tables(0).Rows(0)("Question")

            Dim i As Integer = 0
            For Each dr As DataRow In ds.Tables(1).Rows
                rdoPollOptionList.Items.Add(dr("Answer"))
                rdoPollOptionList.Items(i).Value = dr("PK_OptionId")
                rdoPollOptionList.SelectedIndex = 0

                i = i + 1
            Next
        Catch ex As Exception
            Throw ex
        End Try

    End Sub


0
 
LVL 9

Author Comment

by:Seven price
ID: 24870563
The radio button is getting the option value from the database.


0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24870575
where are you calling this DisplayPoll() ?
Put the Call to this method in If Not Page.IsPostBack
0
 
LVL 9

Author Comment

by:Seven price
ID: 24870588
Anythingin your Page_Load method?  found it thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question