title: VB.NET-Iteration through data table going out of bound
body: <p>i have been trying to iterate through two data table at once to compare them using nested for loop, but the outer loop keep going to out of the conditioned variable.</p>
  
  <pre><code>query_strg = "my query"
  rs = New SqlCommand(query_strg, myconn)
  adap.SelectCommand = rs
  adap.Fill(dset)
  count = dset.Rows.Count
  For k = 0 To (count - 1)
      For j = 0 To (dset1.Rows.Count - 1)
      If (dset1.Rows(j)("name2").ToString() =dset.Rows(k)("name1").ToString() 
      OrElse (dset.Rows(k)("name2").ToString() = "General" 
      OrElse (dset.Rows(k)("name2").ToString() = "general" 
      OrElse (dset.Rows(k)("name2").ToString() = "Reports")))) Then
              dset.Tables(0).Rows(k).Delete()
              dset.Tables(0).AcceptChanges()
              count = dset.Tables(0).Rows.Count
          End If
      Next j
  Next k
  </code></pre>
  
  <p>This is my code.... The dset contain only single column and dset1 contain 5 columns. I need to compare a single column in dset1 to dset and if equal i need to delete that column and also i have performed other comparisons which are mandatory.... </p>
  
  <p>But the problem is the outer for loop goes out of bound resulting in one of the if conditions to throw exception as 'No row available at no.' something like that.... </p>
  
  <p>Need to know why the for loop goes out of bound and if there is not solution for it... I need an alternate idea to perform this action.</p>