Thread: Survey Engine
View Single Post
Old March 2nd, 2008, 03:07 PM
Dennis239 Dennis239 is offline
Registered User
Join Date: Mar 2008
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Survey Engine

Hello. In chapter 4 Survey Engine I found this code. Procedure SaveResponses() writes user responses to the database. I can't understand how does it correlate with N-tier design where Data Access Level is completely independent from Application Level. What I mean.
Dim mform As HttpContext = HttpContext.Current
Dim QuestionIDs As Collection = GetQuestionIDsForSurvey(mform.Request.QueryString("surveyID"))
How this code is supposed to work if we move from website to Windows Application for example?

   Public Shared Function SaveResponses() As Boolean

        Using mConnection As New SqlConnection(Config.ConnectionString)

            ' get the request context...(we can access the values from the form 
            'that the user last posted from here!)
            Dim mform As HttpContext = HttpContext.Current

            'get the list of questions from the db
            Dim QuestionIDs As Collection = GetQuestionIDsForSurvey(mform.Request.QueryString("surveyID"))

            'iterate through each of the question ID's and add the appropriate response
            'to the responses table
            For i As Integer = 0 To QuestionIDs.Count - 1

                'ensure the user selected one of the option buttons for this specific question ID
                If mform.Request.Form.Item("Q" & QuestionIDs(i + 1).ToString()) <> "" Then

                    'Create a command object
                    Dim mCommand As SqlCommand = New SqlCommand("sprocResponseInsertItem", mConnection)

                    'set it to the type of 'stored procedure'
                    mCommand.CommandType = CommandType.StoredProcedure

                    'add in two parameters: the question ID and the choice of the user (A,B,C,or D)
                    mCommand.Parameters.AddWithValue("@questionID", QuestionIDs(i + 1).ToString())
                    mCommand.Parameters.AddWithValue("@selection", mform.Request.Form.Item("Q" & QuestionIDs(i + 1).ToString()))

                    'open the connection and execute the stored procedure

                    'close the connection and dispose of the command

                End If

            Return True

        End Using

    End Function