alander
Well-known member
Hi i wanna print a list of database records off a oledbdatareader, every new row it shld create a new page, however its not working any help appreciated
VB.NET:
Private Sub pDocPaySlip_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pDocPaySlip.PrintPage
Dim sqlConn As New OleDbConnection(connString)
Dim sqlStatement As String = "Select * from PayRoll WHERE Date>=#" + _
Date.Now.Month.ToString + "/1/" + Date.Now.Year.ToString + _
"# AND Date<=#" + Date.Now.Month.ToString + "/" + Date.DaysInMonth(Date.Now.Year, Date.Now.Month).ToString + "/" + Date.Now.Year.ToString + "#"
Dim font As New System.Drawing.Font("Arial", 8, FontStyle.Regular)
Dim sqlCmd As New OleDbCommand(sqlStatement, sqlConn)
sqlConn.Open()
Dim sqlReader As IDataReader = sqlCmd.ExecuteReader()
Dim noOfPage As Integer = 0
While sqlReader.Read
e.Graphics.DrawString(sqlReader.Item(0), font, Brushes.Black, 100, 100)
e.Graphics.DrawString(sqlReader.Item(1), font, Brushes.Black, 100, 150)
e.Graphics.DrawString(sqlReader.Item(2), font, Brushes.Black, 100, 200)
e.Graphics.DrawString(sqlReader.Item(3), font, Brushes.Black, 100, 250)
e.Graphics.DrawString(sqlReader.Item(4), font, Brushes.Black, 100, 300)
e.Graphics.DrawString(sqlReader.Item(5), font, Brushes.Black, 100, 350)
e.HasMorePages = True
End While
e.HasMorePages = False
sqlReader.Close()
sqlConn.Close()
End Sub