Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I try to create online quiz using asp.net with vb and I am using following code in my vb file and getting error
cannot find table 0

VB
Public Class quiz
    Inherits System.Web.UI.Page
    Public CMD As New OleDbCommand
    Public CMDB As New OleDbCommandBuilder
    Dim da As OleDb.OleDbDataAdapter
    Dim con As New OleDb.OleDbConnection
    Dim sql As String
    Public ds As New DataSet
    Public Info As New DataTable
    Dim i As Integer = 0
    Dim scor As Integer = 0
    Dim ans As String
    Dim corect As String


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|learn_english.mdb"
            con.Open()
            sql = "SELECT TOP 5 * FROM quiz where level= 1 ORDER BY Rnd(-10000000*TimeValue(Now())*[id]) "
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds)



            Label1.Text = ds.Tables(0).Rows(0).Item(1).ToString()
            RadioButton1.Text = ds.Tables(0).Rows(0).Item(2).ToString()
            RadioButton2.Text = ds.Tables(0).Rows(0).Item(3).ToString()
            RadioButton3.Text = ds.Tables(0).Rows(0).Item(4).ToString()
            RadioButton4.Text = ds.Tables(0).Rows(0).Item(5).ToString()



        End If


    End Sub
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label3.Text = "choese Ansewer"
        corect = ds.Tables(0).Rows(i).Item(6).ToString()
        If RadioButton1.Checked = True Then
            ans = RadioButton1.Text
        ElseIf RadioButton2.Checked = True Then
            ans = RadioButton2.Text
        ElseIf RadioButton3.Checked = True Then
            ans = RadioButton3.Text
        ElseIf RadioButton4.Checked = True Then
            ans = RadioButton4.Text
        Else
            Label3.Text = "choese Ansewer"
        End If

        If ans = corect Then
            scor = scor + 10


        End If

        If i < 4 Then



            i = i + 1
            Label1.Text = ds.Tables(0).Rows(i).Item(1).ToString()
            RadioButton1.Text = ds.Tables(0).Rows(i).Item(2).ToString()
            RadioButton2.Text = ds.Tables(0).Rows(i).Item(3).ToString()
            RadioButton3.Text = ds.Tables(0).Rows(i).Item(4).ToString()
            RadioButton4.Text = ds.Tables(0).Rows(i).Item(5).ToString()
            con.Close()


        Else
            MultiView1.ActiveViewIndex = 1


            Label2.Text = "your scor is " + scor.ToString()
        End If
    End Sub
End Class


Please help me...
Posted
Updated 10-Feb-15 13:51pm
v3
Comments
ZurdoDev 10-Feb-15 21:24pm    
That means your DataSet is empty.
amosh 11-Feb-15 6:38am    
but it is not empty because i get error when click button next
ZurdoDev 11-Feb-15 7:27am    
It is empty. That's what it means when it says there is no Table 0. It isn't there.

You shouldn't be loading the dataset in page load and then trying to use it later anyway.

1 solution

Hello,

Before use dataset check below condition
VB
If ds.Tables(0) Is Nothing OrElse ds.Tables(0).Rows.Count = 0 Then
        'is really empty
    Else
        'You have a dataset with data.
    End If
 
Share this answer
 

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