The code below is creating a new id instead of following the participant id created ... If the participant enters fname, lname, email, etc a record is created with a participant id (ex. 36). when the participant takes the quiz another participant id is created
(ex. 4) instead of the participant id following the part. (want the quiz table to reflect the 36 particpant id created) ... I'm using cookies. This may be the problem ... Would prefer to use session control. How would I go about this?
Default.asp.vb pg
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
If Profile.IsAnonymous = True Then
Dim n As Integer
n = CInt(Math.Ceiling(Rnd()))
Dim IDNumber As Integer = CInt(Math.Ceiling(Rnd() * n))
Session.Add("ParticipantID", IDNumber)
End If
End If
End Sub
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext.Click
' Define objects
Session("QuizID") = "1"
Dim FirstName As String = txtFirstName.Text
Dim LastName As String = txtLastName.Text
Dim Email As String = txtEmail.Text
Dim Phone As String = txtPhone.Text
Dim FutureEmail As String
If chkEmail.Checked = True Then
FutureEmail = "Yes"
Else
FutureEmail = "No"
End If
Dim aCookie As New HttpCookie("ParticipantID")
aCookie("ParticipantID") = 1
Response.Cookies.Add(aCookie)
Dim strConn As String = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = conn
' Add the parameters.
cmd.Parameters.AddWithValue("@FirstName", FirstName)
cmd.Parameters.AddWithValue("@LastName", LastName)
cmd.Parameters.AddWithValue("@Email", Email)
cmd.Parameters.AddWithValue("@Phone", Phone)
cmd.Parameters.AddWithValue("@chkEmail", FutureEmail)
cmd.CommandText = "INSERT INTO Participants(FirstName, LastName, Email, Phone, FutureEmail) VALUES(@FirstName, @LastName, @Email, @Phone, @chkEmail)"
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Response.Redirect("start.aspx?testid=1&" + Response.Cookies("ParticipantID").Value.ToString() + "")
End Sub
End Class
results.aspx.vb pg
Dim ParticipantQuizDataSource As SqlDataSource = New SqlDataSource()
Dim strConn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = conn
cmd.Parameters.AddWithValue("@QuizID", HttpContext.Current.Session("QuizID").ToString())
cmd.Parameters.AddWithValue("@Score", score.ToString())
cmd.Parameters.AddWithValue("@ParticipantID", HttpContext.Current.Session("ParticipantID"))
bri_lin
Member
1 Points
51 Posts
want to add session instead of cookies
Jun 26, 2012 02:35 PM|LINK
The code below is creating a new id instead of following the participant id created ... If the participant enters fname, lname, email, etc a record is created with a participant id (ex. 36). when the participant takes the quiz another participant id is created (ex. 4) instead of the participant id following the part. (want the quiz table to reflect the 36 particpant id created) ... I'm using cookies. This may be the problem ... Would prefer to use session control. How would I go about this?
Default.asp.vb pg Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.Configuration Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then If Profile.IsAnonymous = True Then Dim n As Integer n = CInt(Math.Ceiling(Rnd())) Dim IDNumber As Integer = CInt(Math.Ceiling(Rnd() * n)) Session.Add("ParticipantID", IDNumber) End If End If End Sub Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext.Click ' Define objects Session("QuizID") = "1" Dim FirstName As String = txtFirstName.Text Dim LastName As String = txtLastName.Text Dim Email As String = txtEmail.Text Dim Phone As String = txtPhone.Text Dim FutureEmail As String If chkEmail.Checked = True Then FutureEmail = "Yes" Else FutureEmail = "No" End If Dim aCookie As New HttpCookie("ParticipantID") aCookie("ParticipantID") = 1 Response.Cookies.Add(aCookie) Dim strConn As String = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim conn As New SqlConnection(strConn) Dim cmd As New SqlCommand() cmd.Connection = conn ' Add the parameters. cmd.Parameters.AddWithValue("@FirstName", FirstName) cmd.Parameters.AddWithValue("@LastName", LastName) cmd.Parameters.AddWithValue("@Email", Email) cmd.Parameters.AddWithValue("@Phone", Phone) cmd.Parameters.AddWithValue("@chkEmail", FutureEmail) cmd.CommandText = "INSERT INTO Participants(FirstName, LastName, Email, Phone, FutureEmail) VALUES(@FirstName, @LastName, @Email, @Phone, @chkEmail)" conn.Open() cmd.ExecuteNonQuery() conn.Close() Response.Redirect("start.aspx?testid=1&" + Response.Cookies("ParticipantID").Value.ToString() + "") End Sub End Classresults.aspx.vb pg
Dim ParticipantQuizDataSource As SqlDataSource = New SqlDataSource()
Dim strConn As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = conn
cmd.Parameters.AddWithValue("@QuizID", HttpContext.Current.Session("QuizID").ToString())
cmd.Parameters.AddWithValue("@Score", score.ToString())
cmd.Parameters.AddWithValue("@ParticipantID", HttpContext.Current.Session("ParticipantID"))
cmd.CommandText = "INSERT INTO ParticipantQuiz (QuizID, Score, ParticipantID) VALUES(@QuizID, @Score, @ParticipantID)"
Denzil Seque...
Member
10 Points
6 Posts
Re: want to add session instead of cookies
Jul 04, 2012 08:38 PM|LINK
Hi ,
Check the following link
http://msdn.microsoft.com/en-us/library/ms178581.aspx
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: want to add session instead of cookies
Jul 05, 2012 04:23 AM|LINK
Hi,
Since ID, is generated every time, you may have to try validating Email!
If the user already taken the test, then you shouldn't create a new ID!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space