Hallo zusammen,
Ich möchte gerne Daten aus meiner DB drucken, das funktioniert auch alles richtig gut. Sofern es wenige Datensätze sind ( die auf eine seite passen). Aber wenn viel mehr Datensätze zu Drucken sind , dann passen sie nicht mehr auf eine Seite ( ist ja klar). Wie kann ich dem genau sagen das er auf der nächsten seite weiter drucken soll. Ich weiss mit e.HasMorePages soll es gehen. Ich versuch nun schon seit Tagen es alleine hinzubekommen. Habe schon soviel ausprobiert aber keine saubere Lösung gefunden / hingekriegt.
Ich habe hier mal meinen Code gepostet wo ihr sehen könnt wie ich die Daten aus der DB aufs Papier bringe.
Wie gesagt mit wenigen Datensätzen funzt es super. Aber dann hört es bei mir aber auch schon auf.
Ich wäre für Hilfe oder Anregungen sehr dankbar.
Private Sub PrintDocument3_PrintPage(sender As Object, e As _
PrintPageEventArgs) Handles PrintDocument3.PrintPage
Dim sql As String
Dim cmd As New OleDb.OleDbCommand
Dim dt As New DataTable
Dim da As New OleDb.OleDbDataAdapter
' Text Ausrichtung
text_rechts.Alignment = StringAlignment.Far 'far= rechts ausgerichtet
text_links.Alignment = StringAlignment.Near 'near ist links
' ausgerichtet
text_mitte.Alignment = StringAlignment.Center ' center ist
' mittig ausgerichtet
con.Open()
sql = "select * from kontakte order by nachname "
cmd.Connection = con
cmd.CommandText = sql
da.SelectCommand = cmd
x_achse = 100
y_achse = 500
e.Graphics.DrawString("Kontaktliste", New Font("Times New Roman", 26, _
FontStyle.Bold), Brushes.Black, y_achse, x_achse, text_links)
'erste zahl startpunkt von links ( Y achse ),zweite zahl ist die höhe
' von oben ( x achse ),dritte zahl ist der endpunkt ( y achse),vierte
' zahl ist die höhe von oben ( x achse )
e.Graphics.DrawLine(Pens.Black, 500, 150, 700, 150)
x_achse = 200
y_achse = 40
da.Fill(dt)
For Each row As DataRow In dt.Rows
e.Graphics.DrawString(row("vorname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse, x_achse, _
text_links)
e.Graphics.DrawString(row("nachname"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 100, x_achse, _
text_links)
e.Graphics.DrawString(row("strasse"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 230, x_achse, _
text_links)
e.Graphics.DrawString(row("plz"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 410, x_achse, _
text_links)
e.Graphics.DrawString(row("wohnort"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 500, x_achse, _
text_links)
e.Graphics.DrawString(row("telefon"), New Font("Times New Roman", _
10, FontStyle.Regular), Brushes.Black, y_achse + 650, x_achse, _
text_links)
e.Graphics.DrawString(row("mobil"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 750, x_achse, _
text_links)
e.Graphics.DrawString(row("email"), New Font("Times New Roman", 10, _
FontStyle.Regular), Brushes.Black, y_achse + 850, x_achse, _
text_links)
e.Graphics.DrawString(row("geburtstag"), New Font("Times New" & _
"Roman", 10, FontStyle.Regular), Brushes.Black, y_achse + 1000, _
x_achse, text_links)
x_achse = x_achse + 30
Next
e.Graphics.DrawString("Ausdruck vom :" & " " & aktuellesDatum, New Font( _
"Times New Roman", 10, FontStyle.Regular), Brushes.Black, 60, 750, _
text_links)
con.Close()
End Sub |