title: VB.NET - "There is no row at position 0" but Records in Database
body: <p>Having a DataSet problem in VB.NET/Access.
  Code should return 1 record and display the results on a form.</p>
  
  <p>Basically when I step through the code in debug mode it returns 1 row and works fine, 
  but when I run the code without breakpoints I get the error message:</p>
  
  <blockquote>
    <p>There is no row at position 0</p>
  </blockquote>
  
  <p>VB.NET 2010 &amp; MS Access 97</p>
  
  <pre><code>Dim sConnectionString As String = "dsn=MyDatabase"
  Dim sSQL As String = ""
  Dim DBConnection As New OdbcConnection(sConnectionString)
  
  Dim dsMaster As New DataSet
  Dim daMaster As New OdbcDataAdapter
  Dim dtMaster As New DataTable
  
  Try   
      DBConnection.Open()
  
      sSQL = "SELECT * FROM myTable"
      daMaster.SelectCommand = New OdbcCommand(sSQL, DBConnection)
      daMaster.Fill(dsMaster, "MasterDataSet")
  
      If dsMaster.Tables(0).Rows.Count &lt;&gt; 0 Then
         dtMaster = dsMaster.Tables(0)
  
         sItem1 = dtMaster.Rows(0).Item(0).ToString
         sItem2 = dtMaster.Rows(0).Item(1).ToString
         sItem3 = dtMaster.Rows(0).Item(2).ToString
      Else
         MessageBox.Show("No Records Available", "Error", MessageBoxButtons.OK)
      End If
  </code></pre>
  
  <ul>
  <li>When I run the code, I get the messagebox saying <em>No Records</em>.</li>
  <li>When I run in debug mode with a breakpoint on the <strong>IF</strong> statement, I get the messagebox saying <em>No Records</em>. </li>
  <li>When I run in debug mode with a breakpoint on the <strong>FILL</strong> statement, I get  1 record returned and the code in <strong>IF</strong> statement executes.</li>
  </ul>
  
  <p>Any ideas?</p>