Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 3rd, 2015, 1:06 PM   #1
Serigraphie
Programmer
 
Serigraphie's Avatar
 
Join Date: Feb 2011
Posts: 31
Rep Power: 0 Serigraphie is on a distinguished road
Help in assigning database value to array value

Hello, Code Masters,

Here I am again today going to seek help and guidance from you.

I have here a manually assigned values to arrays 0 - 19
now my question is, how can I assign values to each array coming from the SQL database?

The catch is, it is a different SQL statement (specifically a different where clause) for each array value. For example:

Dim answers(19) As String

answers(0) = RbAnswers1.SelectedValue
answers(1) = RbAnswers2.SelectedValue
answers(2) = RbAnswers3.SelectedValue
answers(3) = RbAnswers4.SelectedValue
answers(4) = RbAnswers5.SelectedValue
answers(5) = RbAnswers6.SelectedValue
answers(6) = RbAnswers7.SelectedValue
answers(7) = RbAnswers8.SelectedValue
answers(8) = RbAnswers9.SelectedValue
answers(9) = RbAnswers10.SelectedValue
answers(10) = RbAnswers11.SelectedValue
answers(11) = RbAnswers12.SelectedValue
answers(12) = RbAnswers13.SelectedValue
answers(13) = RbAnswers14.SelectedValue
answers(14) = RbAnswers15.SelectedValue
answers(15) = RbAnswers16.SelectedValue
answers(16) = RbAnswers17.SelectedValue
answers(17) = RbAnswers18.SelectedValue
answers(18) = RbAnswers19.SelectedValue
answers(19) = RbAnswers20.SelectedValue


(This one below is what I need help with)

Dim CorrectAnswer(19) As String

CorrectAnswer(0) = "A"
CorrectAnswer(1) = "A"
CorrectAnswer(2) = "A"
CorrectAnswer(3) = "A"
CorrectAnswer(4) = "A"
CorrectAnswer(5) = "A"
CorrectAnswer(6) = "A"
CorrectAnswer(7) = "A"
CorrectAnswer(8) = "A"
CorrectAnswer(9) = "A"
CorrectAnswer(10) = "A"
CorrectAnswer(11) = "A"
CorrectAnswer(12) = "A"
CorrectAnswer(13) = "A"
CorrectAnswer(14) = "A"
CorrectAnswer(15) = "A"
CorrectAnswer(16) = "A"
CorrectAnswer(17) = "A"
CorrectAnswer(18) = "A"
CorrectAnswer(19) = "A"

Dim score As Integer = 0

For i As Integer = 0 To answers.Length - 1
If answers(i) = CorrectAnswer(i) Then
score += 1
End If
Next

lbCorrectAnswerCount.Text = score / 20 * 100


What I want to happen is change the manual assignment of array to getting it from the DB:

Dim CorrectAnswer(19) As String

CorrectAnswer(0) = "A"
CorrectAnswer(1) = "A"
CorrectAnswer(2) = "A"
CorrectAnswer(3) = "A"


to :

CorrectAnswer(0) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 1 and CorrectAnswer = 'Y'"
CorrectAnswer(1) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 2 and CorrectAnswer = 'Y'"

CorrectAnswer(2) = Select AnswerValue from tbl_ECM_Questionnaire where QuestionID = 3 and CorrectAnswer = 'Y'"


and so on...

I did try the data table approach however, my poor programming skills hiner me from achieving the result that I want.
Thank you in advance!
Serigraphie is offline   Reply With Quote
Reply

Bookmarks

Tags
asp.net, sql server, vb.net

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning values of hash with array 12mrsaturns Perl 7 Jul 28th, 2009 10:52 PM
Assigning Values into Random Index's in Array csrocker101 C# 9 Mar 20th, 2008 4:46 AM
Assigning an array of lists deanosrs C 42 Apr 13th, 2006 2:35 PM
Assigning first character of variable into an array IceNeo Visual Basic .NET 1 Nov 10th, 2005 1:13 PM
problem assigning manipulating an array of objects ridley Java 1 Mar 25th, 2005 8:58 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC