title: Showing the messagebox only once in a loop vb.net
body: <p>I have this loop that pops out a message box every time the condition is true.</p>
  
  <pre><code>For i = 0 To DataGridView1.Rows.Count - 1
          Dim c As Boolean
          c = DataGridView1.Rows(i).Cells(0).Value
          If c = True Then
              cmd3.Connection = con
              con.Open()
  
              cmd3.CommandText = "insert into student select * from stud where studentno = '" &amp; DataGridView1.Rows(i).Cells(1).Value.ToString &amp; "' delete from stud where studentno = '" &amp; DataGridView1.Rows(i).Cells(1).Value.ToString &amp; "'"
              dr3 = cmd3.ExecuteReader()
              MessageBox.Show("Account approved.")
              con.Close()
          Else
  
          End If
      Next
  </code></pre>
  
  <p>The messagebox shows as many times as the checked row. And I want to show it just once. I relocate my messagebox everywhere but it does not work. I searched but did not come up for an answer. 
  I tried moving it outside the loop but the problem is, the message box still shows even the condition is false.</p>
  
  <p>Thanks!</p>