title: Invalid attempt to access a field before calling Read()"
body: <p>I have this problem:</p>
  
  <blockquote>
    <p>"Invalid attempt to access a field before calling Read()" </p>
  </blockquote>
  
  <p>The textbox1 to textbox3 is already running but it stuck in textbox4. I searched for an answer for this error but still can't fix. My code down below. Could anyone help?</p>
  
  <pre><code>Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
      With DataGridView1
  
          If .SelectedRows.Count &gt; 0 Then
              For i As Integer = .SelectedRows.Count - 1 To 0 Step -1
  
                  con = New MySqlConnection
                  con.ConnectionString = ServerLocalhost
                  con.Open()
                  ssql = "select * from bookinformation where BookNumber=" &amp; "'" &amp; DataGridView1.Rows(.SelectedRows(i).Index).Cells(0).Value() &amp; "'"
                  dcmd = New MySqlCommand(ssql, con)
                  dreader = dcmd.ExecuteReader
                  If dreader.Read Then
                      TextBox1.Text = dreader.Item("BookNumber")
                      TextBox2.Text = dreader.Item("BooksTitle")
                      TextBox3.Text = dreader.Item("Quantity")
                      TextBox4.Text = dreader.Item("PublicPrice")
                      TextBox5.Text = dreader.Item("OfficeRemit")
                      TextBox10.Text = dreader.Item("StudentRemit")
                      If inchanged = False Then
                          inchanged = True
                          TextBox7.Text = dreader.Item("SaleFund")
                          TextBox6.Text = dreader.Item("Saving")
                          TextBox8.Text = dreader.Item("SalesPerBook")
                          Label15.Text = dreader.Item("TypeofBook")
                          inchanged = False
                      End If
                      If Label15.Text = ("Hard Bound") Then
                          CheckBox3.CheckState = CheckState.Unchecked
                          CheckBox2.CheckState = CheckState.Unchecked
                          CheckBox1.CheckState = CheckState.Checked
                      ElseIf Label15.Text = ("Paper Bound") Then
                          CheckBox3.CheckState = CheckState.Unchecked
                          CheckBox2.CheckState = CheckState.Checked
                          CheckBox1.CheckState = CheckState.Unchecked
                      ElseIf Label15.Text = ("Complete Set") Then
                          CheckBox3.CheckState = CheckState.Checked
                          CheckBox2.CheckState = CheckState.Unchecked
                          CheckBox1.CheckState = CheckState.Unchecked
                      Else
                          CheckBox3.CheckState = CheckState.Unchecked
                          CheckBox2.CheckState = CheckState.Unchecked
                          CheckBox1.CheckState = CheckState.Unchecked
                          MsgBox("No Type Detected!")
                      End If
  
                      TextBox1.Enabled = False
                      TextBox2.Enabled = False
                      TextBox3.Enabled = False
                      TextBox4.Enabled = False
                      TextBox5.Enabled = False
                      TextBox10.Enabled = False
                      TextBox7.Enabled = False
                      TextBox6.Enabled = False
                      TextBox8.Enabled = False
                      CheckBox1.Enabled = False
                      CheckBox2.Enabled = False
                      CheckBox3.Enabled = False
                  ElseIf id = 0 Then
                      MsgBox("No Record Found!", MsgBoxStyle.Information)
                  End If
  
                  '.Rows.RemoveAt(.SelectedRows(i).Index)
              Next
          Else
              ' MsgBox("Please select to Add")
          End If
  
      End With
  </code></pre>