hello I have a Problem to generate random questions according to Number of Questions actually i want randome question which first take the no of questions just like (5,10,15,20,25...) and on this basis show random questions ...
In my Form i am using Four ComboBoxes , 1 DataGridview and 1 Button Control ... ComBoBox1 is for Modules ,ComboBox2 is for Topics, ComboBox3 is for Levels and ComboBox4 is for No of Questions...
and when i select the module then shows topic of selected module to ComboBox2 and then i select the level then shows random question according to level this is working but i want that this work but with no of question means when we click on numbers then shows randome question according to numbers,levels,Module and topic.
My Code Is:
Public Class Form1
Dim cn As New SqlConnection("Data Source=NIDA-PC\SQLEXPRESS;Initial Catalog=Finaldb;Integrated Security=True")
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim qry As String
Dim dt As New DataTable
Dim dt1 As New DataTable
Dim qry1 As String
Dim qry3 As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.Close()
cn.Open()
qry = "Select Module_ID,Module_Name from Module_tbl"
da = New SqlDataAdapter(qry, cn)
ds = New DataSet()
da.Fill(ds, "tab")
ComboBox1.DataSource = ds.Tables("tab")
ComboBox1.DisplayMember = "Module_Name"
ComboBox1.ValueMember = "Module_ID"
ComboBox1.Text = ""
cn.Close()
cn.Close()
cn.Open()
qry1 = "Select Topic_ID,Topic_Name from topic_tbl"
da = New SqlDataAdapter(qry1, cn)
ds = New DataSet()
da.Fill(ds, "tab")
ComboBox2.DataSource = ds.Tables("tab")
ComboBox2.DisplayMember = "Topic_Name"
ComboBox2.ValueMember = "Topic_ID"
ComboBox2.Text = ""
cn.Close()
ComboBox3.Items.Add("1")
ComboBox3.Items.Add("2")
ComboBox3.Items.Add("3")
ComboBox4.Items.Add("5")
ComboBox4.Items.Add("15")
ComboBox4.Items.Add("20")
ComboBox4.Items.Add("25")
ComboBox4.Items.Add("30")
ComboBox4.Items.Add("35")
ComboBox4.Items.Add("40")
ComboBox4.Items.Add("45")
ComboBox4.Items.Add("50")
ComboBox4.Items.Add("55")
ComboBox4.Items.Add("60")
ComboBox4.Items.Add("65")
ComboBox4.Items.Add("70")
ComboBox4.Items.Add("75")
ComboBox4.Items.Add("80")
ComboBox4.Items.Add("85")
ComboBox4.Items.Add("90")
ComboBox4.Items.Add("95")
ComboBox4.Items.Add("100")
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
qry3 = "SELECT Question,Image_Data,Level_ID FROM Question_tbl where Level_ID= '" & ComboBox3.SelectedItem & "'And Topic_ID= '" & ComboBox2.SelectedValue.ToString & "' ORDER BY NEWID()"
da = New SqlDataAdapter(qry3, cn)
dt1.Clear()
da.Fill(dt1)
ComboBox2.Focus()
ComboBox3.Focus()
DataGridView1.DataSource = dt1
cn.Close()
End Sub
Dim qry6 As String
Dim Module_ID As Integer
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
cn.Close()
cn.Open()
Try
Module_ID = Convert.ToInt32(ComboBox1.SelectedValue.ToString)
Catch ex As Exception
Return
End Try
cn.Close()
cn.Close()
cn.Open()
qry6 = "Select Topic_ID,Topic_Name from Topic_tbl where Module_ID = '" & Module_ID & "'"
da = New SqlDataAdapter(qry6, cn)
dt.Clear()
da.Fill(dt)
ComboBox1.Focus()
ComboBox2.DataSource = dt
cn.Close()
End Sub
End Class