I have a web app I am building that has primarily multiple choice questions with a few short answers. As is all the answers are put into the database via stored procedure, and then are extracted and corrected using a different procedure. While the short answer questions are included in the queries they are not being printed to the page, instead i have them also stored in a session variable and and printed in their respective textboxes, the problem is the reviewer can no longer see them if the session is timed out. So I am wondering how in VB.net do you extract a specific row from a query and then work with it from there.
this is what i have currently
Dim P2Ans As String
P2Ans = Session("Part2")
Dim Part2Txt As New ArrayList(P2Ans.Split("|"c))
Normal.Text = Part2Txt(0)
Normal2.Text = Part2Txt(1)
Normal3.Text = Part2Txt(2)
what i want is something like this
Dim P2Ans As String
P2Ans = Select.Tables(Answers).Where("QuestionID =X") 'from there take the answer out of the column "Question Answer"
Dim Part2Txt As New ArrayList(P2Ans.Split("|"c))
Normal.Text = Part2Txt(0)
Normal2.Text = Part2Txt(1)
Normal3.Text = Part2Txt(2)
i dont know if this is possible or best practice, so any advice would be great.
my answer: something like this
Dim queryString As String = "SELECT questionAnswer FROM Submissions where submissionid =" + SID + "and questionNumber = 1"
Using connection As New SqlConnection(My.Settings.ConnString)
Dim command As New SqlCommand(queryString, connection)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
You could use an SqlCommand object, pass it the query (i.e. SELECT answer FROM answers WHERE questionid = ‘x’) and then use SqlDataReader to retrieve the answer and save it to a variable and / or control on your form.