错误 - 找不到表0 [英] error - Cannot find table 0

查看:67
本文介绍了错误 - 找不到表0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我尝试使用带有vb的asp.net创建在线测验,我在我的vb文件中使用以下代码并收到错误

找不到表0



 公开 班级测验
继承 System.Web.UI.Page
公共 CMD 作为 OleDbCommand
公共 CMDB 作为 OleDbCommandBuilder
Dim da As OleDb.OleDbDataAdapter
Dim con As OleDb.OleDbConnection
Dim sql 作为 字符串
公共 ds 作为 DataSet
公开信息作为 DataTable
Dim i 作为 整数 = 0
Dim scor < span class =code-keyword> As 整数 = 0
< span class =code-keyword> Dim ans As String
< span class =code-keyword> Dim corect As String


受保护的 Sub Page_Load( ByVal 发​​件人作为 对象,< span class =code-keyword> ByVal e As System.EventArgs)句柄 < span class =code-keyword> Me .Load
如果 IsPostBack 然后
con.ConnectionString = 提供者= Microsoft.Jet.OLEDB.4.0;数据源= | DataDirectory | learn_english.mdb
con.Open()
sql = SELECT TOP 5 * FROM quiz其中level = 1 ORDER BY Rnd(-10000000 * TimeValue(Now())* [id])
da = OleDb.OleDbDataAdapter(sql,con)
da.Fill(ds)



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



结束 如果


结束 Sub

受保护的 Sub Button1_Click( ByVal sender As 对象 ByVal e As System.EventArgs)句柄 Button1.Click
Label3.Text = choese Ansewer
corect = ds.Tables( 0 )。行(i).Item( 6 ) .ToString()
如果 RadioButton1.Checked = True 然后
ans = RadioButton1.Text
ElseIf RadioButton2.Checked = True 然后
ans = RadioButton2.Text
ElseIf RadioButton3.Checked = True 然后
ans = RadioButton3.Text
ElseIf RadioButton4.Checked = True 然后
ans = RadioButton4.Text
Else
Label3.Text = choese Ansewer
结束 如果

如果 ans = corect 那么
scor = scor + 10


结束 如果

如果 i< 4 然后



i = i + < span class =code-digit> 1
Label1.Text = ds.Tables( 0 )。行(i).Item( 1 )。ToString()
RadioButton1.Text = ds.Tables( 0 )。行(i).Item( 2 )。ToString()
RadioButton2.Text = ds.Tables( 0 ).Rows(i).Item( 3 )。ToString()
RadioButton3.Text = ds.Tables( 0 )。行(i).Item( 4 )。ToString()
RadioButton4.Text = ds.Tables( 0 )。行(i).Item( 5 )。ToString()
con。关闭()


否则
MultiView1.ActiveViewIndex = 1


Label2.Text = 你的scor是 + scor.ToString()
结束 如果
结束 Sub
结束 班级





请帮助我...

解决方案

您好,



使用数据集之前检查以下条件

 如果 ds.Tables( 0   Nothing   OrElse  ds.Tables( 0 ).Rows.Count =  0  然后 
' 真的是空的
否则
' 您有一个包含数据的数据集。
结束 如果


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

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...

解决方案

Hello,

Before use dataset check below condition

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


这篇关于错误 - 找不到表0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆