title: Split output result by n and loop
body: <p>I'm solving an issue where I need to create one PDF form.</p>
  
  <p>That PDF form has 8 sections where I need to put info about and looks like shown on picture (only 4 shown).</p>
  
  <p>The point is that my query will return 0 - n different results. So I need to split by 8 and post on different pages. </p>
  
  <p>I tried like shown below but that seems not to work since I always load a new document. Does anyone have some advice how to make it?</p>
  
  <p><a href="https://i.stack.imgur.com/HBtH1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HBtH1.png" alt="enter image description here"></a></p>
  
  <pre class="lang-vb prettyprint-override"><code>Try
      Dim sCommand As OleDb.OleDbCommand
      sCommand = New OleDb.OleDbCommand("SELECT a,b,c Query to fetch n results ", _dbCon)
      sCommand.CommandTimeout = 0
      Dim _dbREADER As OleDb.OleDbDataReader
      _dbREADER = sCommand.ExecuteReader
      Dim dt As DataTable = New DataTable()
      dt.Load(_dbREADER)
  
      Dim totalPages As Integer = dt.Rows.Count / 8
      Dim currentPage As Integer = 1
      Dim rowCounter As Long = 0
  
      If dt.Rows.Count &gt; 0 Then
          For Each row In dt.Rows
              rowCounter += 1
  
              If rowCounter = 8 Then
                  currentPage += 1
                  rowCounter = 0
              End If
  
              _pdfDocumentOutput = System.IO.Path.GetTempPath() &amp; "MailingForm_" &amp; currentPage &amp; ".pdf"
              SaveFromResources(_pdfDocument, My.Resources.template)
  
              Using reader As New PdfReader(_pdfDocument)
                  Using stamper As New PdfStamper(reader, New IO.FileStream(_pdfDocumentOutput, IO.FileMode.Create))
                      Dim fontName As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SCRIPTIN.ttf")
                      Dim bf As BaseFont = BaseFont.CreateFont(fontName, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
  
                      Dim pdfForm As AcroFields = stamper.AcroFields
                      pdfForm.AddSubstitutionFont(bf)
                      pdfForm.SetField(rowCounter - 1 &amp; "0", row("Customer")) 'Checks the top radiobutton of the VrPr4 field
                      pdfForm.SetField(rowCounter - 1 &amp; "1", row("Address"))
                      pdfForm.SetField(rowCounter - 1 &amp; "2", row("Location"))
                      stamper.FormFlattening = True
                  End Using
              End Using
          Next
      End If
  
      Status.Text = "Store info loaded ! "
  Catch ex As Exception
      Status.Text = ex.Message
  End Try
  </code></pre>