Hi! I am creating an entrance examination and what I want to do is get all the questions which belong to the same Year Level (e.g.first year) from a table and display the first question into a rich text box and when the next button is clicked, the second row from the table will display. Thanks God Bless! :D

Recommended Answers

All 17 Replies

OoOps! I almost forgot, my choices are to be displayed on a radio button. :)

can u clear little bit of your concept..? may a screen shot or a little code would do

can u clear little bit of your concept..? may a screen shot or a little code would do

Select Question from Questions table where year=@year
fill the dataset with Questions and Show only record. u can use the Index property of grid and then on clik event of button get the row of next index hide other rows

Uhm, I have a table named "Questions" having column name Question and LevelID.

On my form, I have loaded the question having the same LevelID value which is 9 equivalent to first year. I have more than one question to be loaded, and the first question is loaded on my text box on form load, however how would I show the next questions to the text box after clicking the "NEXT QUESTION" button. Thanks! God Bless. :)

How you are loading the textbox now? are you getting the data from db to dataset?

On what I did on my uploaded pic, I didn't use dataset. I just declare on my form_load and select statement and display. :(

Load the questions to dataset and on click event loop through the dataset to get next questions and assign that to list box

Okay, hopefully I can do it. I am a newbie and have less knowledge about dataset and looping. :)

does the value to radio buttons come from another table?

@sandeepparekh9 - Yes, the value of my buttons come from QuestionChoices table.

suppose u have 30 questions for level 1.

define a variable

dim tota_level_1 as integer = 1

now each time you press next button then increment the total_level_1 variable.

total_level_1 += 1

and fetch the question in textbox according to a sql query like this

' this query goes in next button event
strquery = "select * from questions where question_id = '" + total_level_1 + "'"

so each time u press next button total_level_1 increases by one and u get the next question_id

I'm so sorry but I don't know where to manipulate those. As I load my form, I selected the questions of Level1 value and displays it to the textbox. That works, what I need to do is just to show the next question. I'm so sorry if it's kinda stupid.

Dim ds As New DataSet
        Dim i As Integer
        i = 0
        adap2 = New OleDbDataAdapter("SELECT Question FROM Questions WHERE LevelID = 9", mycurrentconnection)
        adap2.Fill(ds, "Question")
        dtgrdQuestions.DataSource = ds.Tables("Question")

        If (i < ds.Tables(0).Rows.Count - 1) Then
            rtxtQuestion.Text = ds.Tables(0).Rows(i)("Question").ToString
            i = +1

        Else
            MsgBox("No records found")
        End If

        mycurrentconnection.Close()
    End Sub

but still, after loading the first question, I can't load the next one. Thanks! God Bless. :)

hi. Find the attachment of demo application

i have made an simple application for you regarding your concept. please see it and u will under stand how to make your application

i have used vs2005 with MS-ACCESS

the form has a textbox , 4 radio button and a next button

here is the whole code:

Imports System.Data.OleDb
Public Class Form1
    Dim conn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim strQ As String = String.Empty
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim i As Integer = 0


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;")

        ' filling the textbox of Question
        cmd = New OleDbCommand("Select * from Questions", conn)
        da = New OleDbDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, "Questions")

        'filling the radiobutton according to the question number
        cmd = New OleDbCommand("Select * from QuestionChoices", conn)
        da = New OleDbDataAdapter(cmd)
        da.Fill(ds, "QuestionChoices")



        Me.TextBox1.Text = ds.Tables("Questions").Rows(i)(1).ToString()
        Me.RadioButton1.Text = ds.Tables("QuestionChoices").Rows(i)(1).ToString()
        Me.RadioButton2.Text = ds.Tables("QuestionChoices").Rows(i)(2).ToString()
        Me.RadioButton3.Text = ds.Tables("QuestionChoices").Rows(i)(3).ToString()
        Me.RadioButton4.Text = ds.Tables("QuestionChoices").Rows(i)(4).ToString()

        ' increment i to get next question
        i = i + 1

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Me.TextBox1.Text = ds.Tables("Questions").Rows(i)(1).ToString()
        Me.RadioButton1.Text = ds.Tables("QuestionChoices").Rows(i)(1).ToString()
        Me.RadioButton2.Text = ds.Tables("QuestionChoices").Rows(i)(2).ToString()
        Me.RadioButton3.Text = ds.Tables("QuestionChoices").Rows(i)(3).ToString()
        Me.RadioButton4.Text = ds.Tables("QuestionChoices").Rows(i)(4).ToString()

        i = i + 1
    End Sub
End Class

Thank you very much! I understand the concept. Sorry for disturbing you. Thank you again! God Bless. :)

Great! It's working, however I don't know why there's an error message saying that says Cannot find column 3 which I have. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.