Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Q&A datareader

Posted on 2006-11-09
9
Medium Priority
?
235 Views
Last Modified: 2010-08-05
I have an app that pulls in data from an Access db.
There are two tables - Questions & Answers

I need my form load to call a sub, LoadQuestion, which should read a field named [Correct]
If this field has only one character, display x number of radio buttons ([C])
If it's multiple characters (comma seperated), display x number of check boxes ([B,E])

My default instances are radOption and chkOption.
I'm also using:
Dim cn As OleDbConnection, cmd As OleDbCommand, dr As OleDbDataReader
Dim strCon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Quizz.mdb"

and in my form load,
cmd = New OleDbCommand("SELECT QuesID, QuestionText, OptA, OptB, OptC, OptD, OptE, OptF, Correct FROM tblQuestions, tlbAnswers WHERE QuestionID=AnswerID", cn)

Anyone willing to help me get this running? :^)
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 10

Accepted Solution

by:
gangwisch earned 1500 total points
ID: 17906097
cmd = New OleDbCommand("SELECT QuesID, QuestionText, OptA, OptB, OptC, OptD, OptE, OptF, Correct FROM tblQuestions, tlbAnswers WHERE QuestionID=AnswerID", cn)
dim dr as oledbdatareader = cmd.executereader()
if dr.read then
if len(dr("Correct"))=1 then
'make radio button
dim a as new radiobutton
a.text=dr("opta")
dim b as new radiobutton
b.text=dr("optb")
dim c as new radiobutton
c.text=dr("optc")
dim d as new radiobutton
d.text=dr("optd")
dim e as new radiobutton
e.text=dr("opte")
dim f as new radiobutton
f.text=dr("optf")
me.controls.add(a)
me.controls.add(b)
me.controls.add(c)
me.controls.add(d)
me.controls.add(e)
me.controls.add(f)
else
'make check box
dim a as new checkbutton
a.text=dr("opta")
dim b as new checkbutton
b.text=dr("optb")
dim c as new checkbutton
c.text=dr("optc")
dim d as new checkbutton
d.text=dr("optd")
dim e as new checkbutton
e.text=dr("opte")
dim f as new checkbutton
f.text=dr("optf")
me.controls.add(a)
me.controls.add(b)
me.controls.add(c)
me.controls.add(d)
me.controls.add(e)
me.controls.add(f)
end if
end if
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17907250
How would I reference the created control?
For instance, if I have a variable/array (CorrectAnswer), how would I validate that the correct radio/checkbox was clicked?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17908800
This is working for me - but I'm not sure how to reference that the correct answer(s) were chosen.  I can't seem to position the controls properly either... :|  They look 'ok', but it seems I've got a straggler at the top, for some reason...
       
        For Each dR In dv.Table.Rows 'ds.Tables(0).Rows
            With dR
                If Len(dR.Item("Correct")) = 1 Then
                    'make radio button
                    a = New RadioButton
                    b = New RadioButton
                    c = New RadioButton
                    d = New RadioButton
                    e = New RadioButton
                    f = New RadioButton
                Else
                    'make check box
                    a = New CheckBox
                    b = New CheckBox
                    c = New CheckBox
                    d = New CheckBox
                    e = New CheckBox
                    f = New CheckBox
                End If
 
               With Me.Controls
                    .Add(a)
                    .Add(b)
                    .Add(c)
                    .Add(d)
                    .Add(e)
                    .Add(f)
                End With

                With a
                    .Text = dR("optA")
                    .Location = New System.Drawing.Point(12, 56)
                    .Width = 400
                End With
                With b
                    .Text = dR("optB")
                    .Location = New System.Drawing.Point(12, 102)
                    .Width = 600
                End With
                With c
                    .Text = dR("optC")
                    .Location = New System.Drawing.Point(12, 148)
                    .Width = 800
                End With
                With d
                    .Text = dR("optD")
                    .Location = New System.Drawing.Point(12, 194)
                    .Width = 800
                End With
                With e
                    If Not IsDBNull(dR("optE")) Then
                        .Text = dR("optE")
                        .Location = New System.Drawing.Point(12, 240)
                        .Width = 800
                    Else
                        e.Visible = False
                    End If
                End With
                With f
                    If Not IsDBNull(dR("optF")) Then
                        .Text = dR("optF")
                        .Location = New System.Drawing.Point(12, 285)
                        .Width = 800
                    End If
                End With
            End With
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17915859
SirBounty,

Still need a hand with this one?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17915871
Yes - I've opened another question related to it.
Part of this has been answered - how to distinguish between the radio/checkbox...
So,perhaps I should close this and work off the other to avoid a duplicate question.
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17916199
Fair enough.

Just as a minor note.... you might want to consider refactoring this so that your code is more maintainable...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17916231
Not sure I follow you there?  Did I get off on the wrong foot anyways? : \
0
 
LVL 24

Expert Comment

by:Jeff Certain
ID: 17916333
Refactoring is rearranging your code so it doesn't hurt to look at it... or make changes :)

So, the above code might look like:

Public Sub MakeControls()
    For Each dr In dv.Table.Rows
      If Len(dR.Item("Correct")) = 1 Then
        MakeRadioButtons(dr)
      Else
        MakeCheckBoxes(dr)
      End If
    Next
  End Sub

  Public Sub MakeCheckBoxes(ByVal dr As DataRow)
    MakeCheckBox("A", dr("optA"), 12, 56, 400)
    MakeCheckBox("B", dr("optB"), 12, 102, 600)
    MakeCheckBox("C", dr("optC"), 12, 158, 800)
    MakeCheckBox("D", dr("optD"), 12, 224, 800)
    MakeCheckBox("E", dr("optE"), 12, 280, 800)
    MakeCheckBox("B", dr("optF"), 12, 336, 800)
  End Sub

  Public Sub MakeCheckBox(ByVal letter As String, ByVal text As Object, ByVal top As Integer, ByVal left As Integer, ByVal width As Integer)
    If Not text Is DBNull.Value Then
      Dim chk As New CheckBox
      chk.Text = letter & ") " & text.ToString
      chk.Top = top
      chk.Left = left
      chk.Width = width
      Me.Controls.Add(chk)
    End If
  End Sub

  Public Sub MakeRadioButtons(ByVal row As DataRow)

  End Sub

  Public Sub MakeRadioButton()

  End Sub
0
 
LVL 67

Author Comment

by:sirbounty
ID: 17916751
Thanx for that - I'll look into adjusting it (and was going to at some point down the line).
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question