3

I'm currently working on a small quiz type app that populates questions and answers from an SQL .mdf database. I've been looking for a control in Visual Studio 2012 that could hold the four answers (preferably checkboxlist).

The only problem is I have the questions saved in different columns, answer1, answer2 etc.

The main question is, is there a way to populate the checkboxlist control with multiple data fields rather than just one?

I tried using four separate checkboxlists, but this made validation extremely difficult (Only one option should be selected). Does anyone have any advice or suggest how I could insert the four columns into a control that I could validate?

I read online about combining the answers using sql ie. SELECT Answer1 + ' ' + Answer2, this works but again I don't know how to integrate this into a combo box list.

2
  • What code have you got so far? Commented Mar 15, 2014 at 1:24
  • Check out SQL Server unpivot syntax Commented Mar 15, 2014 at 3:43

1 Answer 1

1

there are two easy ways:

on the database side you could use:

SELECT convert(Char,[Answer1]) FROM [TABLE1] union ALL  SELECT convert(char,[Answer2])   FROM [TABLE1] 

From the application side you could use Merge:

 dim dt as new datatable
dt = SQLdataTable("SELECT [Answer1]  FROM [TABLE1]")
dt.Merge(SQLdataTable("SELECT [Answer2]  FROM [TABLE1]").Copy)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.