Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

CorrectAnswer(0) = select data where fieldValue = 1
CorrectAnswer(1) = select data where fieldValue = 2
CorrectAnswer(2) = select data where fieldValue = 3
CorrectAnswer(3) = select data where fieldValue = 4


and so on..

Any additional inputs will be greatly appreciated.

I tried by the way the use of data table however I am not sure how to do it because of the condition (different where clause for each array value).

Hoping you are able to get my meaning.

Thank you!
Posted

1 solution

For this particular case why have not you tried writing an SP that tailor your result in the defined fashion. The skeleton of SP could be like

SP Begin

 SELECT IndexId, ValueofFunc(Index)
 FROM  TABLE
 WHERE INDEXID BETWEEN 1 AND 19

SP END

Function ValueofFunc(Indx)
Begin

   SELECT Data
   FROM TABLE
   WHERE INDEXID = Index

END


This will not only reduce your round trips but also reduce complexity of Business Layer code as all you have to do is bind the result to an array
 
Share this answer
 
Comments
serigraphie 2-Mar-15 11:23am    
Hi Sir,
While I would love to take the "defined fashion" approach, my programming capabilities hinder me. So my question would be, should I call that procedure from my application and pass on some parameters? Hope you can guide me in achieving it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900