title: IndexOutOfRangeException was Unhandled. Cannot find table 0
body: <p>can anyone please help on how to fix this error? im getting an error "Error:Syntax error(missing operator)in query expression '''ans'." this is my code:</p>
  
  <pre><code>Imports System.Data
  Imports System.Data.OleDb
  Public Class frmExam : Inherits System.Windows.Forms.Form
   Dim ds As New DataSet()
   Dim qno() As Integer
   Dim pos As Integer
  
  Private Sub btnFinish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFinish.Click
      ProcessAnswer()
      Dim i, marks As Integer
      Dim dr As DataRow
      marks = 0
      For i = 0 To NOQ - 1
          dr = ds.Tables(0).Rows(qno(i))
          If Not IsDBNull(dr.Item("ans")) AndAlso dr.Item("CorrectAns") = dr.Item("ans") Then
              marks += 1
          End If
      Next
  
      Try
          con.Open()
          Dim cmd As New OleDbCommand("insert into stud values(stud.nextval,'" &amp; SubjectCode &amp; "','" &amp; Username &amp; "','" &amp; marks &amp; ")", con)
          MsgBox(cmd.CommandText)
          cmd.ExecuteNonQuery()
          Dim msg As String
          msg = "UserName         : " &amp; Username &amp; ControlChars.CrLf &amp; _
                  "Subject        : " &amp; SubjectCode &amp; ControlChars.CrLf &amp; _
                  "Total Questions : " &amp; NOQ &amp; ControlChars.CrLf &amp; _
                  "Marks           : " &amp; marks
          MsgBox(msg, "Result")
      Catch ex As Exception
          MsgBox(ex.Message)
      Finally
          If con.State &lt;&gt; ConnectionState.Closed Then
              con.Close()
          End If
      End Try
      Me.Dispose()
  End Sub
  
  Private Sub frmExam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      ReDim qno(NOQ)
      Try
          Dim da As New OleDbDataAdapter("select Question, Ans1, Ans2, Ans3, Ans4, CorrectAns, QType, '' ans from question where SubjectCode = " &amp; SubjectCode, con)
          da.Fill(ds, "question")
      Catch ex As Exception
          MsgBox("Error:" &amp; ex.Message)
          Me.Dispose()
      End Try
  
      Randomize()
      Dim totrows As Integer
  
      totrows = ds.Tables(0).Rows.Count
      Dim i, r, j As Integer
      Dim present As Boolean
      i = 0
      Do While i &lt; 5
          r = CInt((totrows - 1) * Rnd())
          present = False
          For j = 0 To i
              If r = qno(j) Then
                  present = True
                  Exit For
              End If
          Next
  
          If Not present Then
              qno(i) = r
              i = i + 1
          End If
      Loop
      pos = 0
      DisplayQuestion()
  End Sub
  Sub DisplayQuestion()
      Dim row As DataRow
  
      lblQno.Text = Str(pos + 1) &amp; "/" &amp; NOQ
      lblSubcode.Text = "Subject : " &amp; SubjectCode
      row = ds.Tables(0).Rows(qno(pos))
  
      txtQuestion.Text = row.Item(0)
      txtAns1.Text = row.Item(1)
      txtAns2.Text = row.Item(2)
      txtAns3.Text = row.Item(3)
      txtAns4.Text = row.Item(4)
  
      lblQNo2.Text = Str(pos + 1) &amp; "/" &amp; NOQ
      lblSubCode2.Text = "Subject:" &amp; SubjectCode
      row = ds.Tables(0).Rows(qno(pos))
  
      txtQuestion2.Text = row.Item(0)
      txtAnsTrue.Text = row.Item(1)
      txtAnsFalse.Text = row.Item(2)
  
      lblQNo3.Text = Str(pos + 1) &amp; "/" &amp; NOQ
      lblSubcode.Text = "Subject : " &amp; SubjectCode
      row = ds.Tables(0).Rows(qno(pos))
  
      txtQuestion3.Text = row.Item(1)
      txtAns.Text = row.Item(2)
  
  
      End Sub
  
  Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
      ProcessAnswer()
      If pos &lt; NOQ - 1 Then
          pos = pos + 1
          DisplayQuestion()
      Else
          Beep()
      End If
  End Sub
  
  Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
      ProcessAnswer()
      If pos &gt; 0 Then
          pos = pos - 1
          DisplayQuestion()
      End If
  End Sub
  Public Sub ProcessAnswer()
      Dim row As DataRow
      Dim ans As String = ""
      row = ds.Tables(0).Rows(qno(pos))
      If rdbtnAns1.Checked Then
          ans = "1"
      End If
      If rdbtnAns2.Checked Then
          ans = "2"
      End If
      If rdbtnAns3.Checked Then
          ans = "3"
      End If
      If rdbtnAns4.Checked Then
          ans = "4"
      End If
  
      If rdbtnTrue.Checked Then
          ans = "1"
      End If
      If rdbtnFalse.Checked Then
          ans = "2"
      End If
  
      If txtAns.Text = "" Then
          ans = "txtAns"
      End If
      ds.Tables(0).Rows(qno(pos)).Item("Ans1") = ans
  End Sub
  
  Private Sub btnPrev2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev2.Click
      ProcessAnswer()
      If pos &gt; 0 Then
          pos = pos - 1
          DisplayQuestion()
      End If
  End Sub
  
  Private Sub btnNext2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext2.Click
      ProcessAnswer()
      If pos &lt; NOQ - 1 Then
          pos = pos + 1
          DisplayQuestion()
      Else
          Beep()
      End If
  End Sub
  
  Private Sub btnPrev3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev3.Click
      ProcessAnswer()
      If pos &gt; 0 Then
          pos = pos - 1
          DisplayQuestion()
      End If
  End Sub
  
  Private Sub btnNext3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext3.Click
      ProcessAnswer()
      If pos &lt; NOQ - 1 Then
          pos = pos + 1
          DisplayQuestion()
      Else
          Beep()
      End If
  End Sub
  End Class
  </code></pre>
  
  <hr>
  
  <p>this is the highlighted texxt:totrows = ds.Tables(0).Rows.Count</p>