title: Print in VB.NET 2010
body: <p>I want to print on a Passbook (paper book used to record bank transactions) using a passbook printer (Epson PLQ 20) Using VB.NET 2010. </p>
  
  <p>My current mysql table structure is,</p>
  
  <pre><code>1. tblLoanRegistry(LoanID pk, EMPNumber, Date, Amount, NoOfInstallments, Teller)
  2. tblLoanAccount(ID pk, LoanID fk, Date, Payment, Interest, Total, Auto bool, Installment int, teller)
  </code></pre>
  
  <p>My problems are:</p>
  
  <ol>
  <li>How to detect the last row printed?</li>
  <li>How to print the first row that not printed, on the correct position of the book (Correct line). </li>
  </ol>
  
  <p>I have decided to add a field "Printed" (Boolean) in each table above mentioned. To get the printed or not. I can print text, numbers etc using the same printer in vb.net (Eg: Account holders details on the front page). But I'm facing above mentioned problems when printing transactions. Your help/ opinions highly appreciated.</p>
  
  <p><strong>More Information:</strong>
  Actually I developed a web based account handling system using php and mysql for a non profit organisation as the my project of the degree. Now they want to print transactions on a passbook as I described before. </p>
  
  <p>Therefore I am creating an application using VB.NET (I am totally new to VB.NET. But have experience in vb6) while I am learning it. I have managed to simple printing but this is something different. </p>
  
  <p>I have no good idea to solve above mentioned two problems. </p>
  
  <p><strong>Update:</strong>
  I did it in different (may be a bad) way. 
  On click event of the print button.</p>
  
  <pre><code>    Dim sqlLoan As String
  
      conn = New MySqlConnection(cnString)
  
      sqlLoan = "SELECT tblLoanAccount.Date,if(Installment = 0, 'Interest', concat('Installment : ', Installment)) as Description, tblLoanAccount.Payment, tblLoanAccount.Interest, " &amp;
          " tblLoanAccount.Total, tblLoanAccount.Auto, tblLoanAccount.Installment FROM tblLoanAccount join tblloanRegistry on  tblloanRegistry.LoanID = tblLoanAccount.LoanID " &amp;
          " where(tblloanRegistry.EMPNumber = " &amp; cmbEMPN.Text &amp; " And tblLoanAccount.LoanID = tblLoanRegistry.LoanID) AND tblLoanAccount.Total &lt;&gt; 0 ORDER BY tblLoanAccount.ID"
  
      Using conn As New MySqlConnection(cnString)
          Using cmd As New MySqlCommand(sqlLoan, conn)
              conn.Open()
              Using myReader As MySqlDataReader = cmd.ExecuteReader()
                  Using writer As StreamWriter = New StreamWriter("c:\file.txt")
                      While myReader.Read()
                          writer.WriteLine("{0}, {1}, {2}, {3}, {4}", myReader.Item(0), myReader.Item(1), myReader.Item(2), myReader.Item(3), myReader.Item(4))
                      End While
                  End Using
                  Call Printing()
              End Using
          End Using
      End Using
  
      ' Print the file. 
  Public Sub Printing()
      Try
          streamToPrint = New StreamReader(("c:\file.txt"))
          Try
              printFont = New Font("Arial", 10)
              Dim pd As New PrintDocument()
              AddHandler pd.PrintPage, AddressOf pd_PrintPage
              ' Print the document.
              pd.Print()
          Finally
              streamToPrint.Close()
          End Try
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  End Sub 'Printing
  </code></pre>
  
  <p>And other codes are as msdn <a href="http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx" rel="nofollow">PrintDocument Class</a>.</p>