0 Replies - 272 Views - Last Post: 07 March 2013 - 09:46 PM Rate Topic: -----

#1 Flintvic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 29-October 12

How can I print my database as a Report?

Posted 07 March 2013 - 09:46 PM

Hi,

I am stuck at a fork in the road. Note that I am trying to print out a report with a database from Access. I have considered two options. Just to format the printpreviewcontrol using printdocument and loop the data from the table in the report or to fill the data in a datagridview and just print that. The problem I'm having with both of these options is for one I need a little help on how to load the data onto the report from the database and two If I were to just print the datagridview how print the whole datagrid and not a small part? Sorry I'm a beginner. Thanks

Here is my code so far.
This is the code of the printing form which displays the printpreview. I commented out the database code, just to use option one but yes the data does show up on the grid if I remove it.
Public Class frmPrint

    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        'Dim bm As New Bitmap(Me.DataGridView1.Width, Me.DataGridView1.Height)
        'DataGridView1.DrawToBitmap(bm, New Rectangle(100, 100, Me.DataGridView1.Width, Me.DataGridView1.Height))
        'e.Graphics.DrawImage(bm, 100, 200)


        Dim HeaderFont As Font = New Drawing.Font("Times New Roman", 30, FontStyle.Bold)
        Dim Header2Font As Font = New Drawing.Font("Times New Roman", 25, FontStyle.Bold)
        Dim BodyFont As Font = New Drawing.Font("Calibri", 16, FontStyle.Bold)
        Dim point1 As New Point(100, 200)
        Dim point2 As New Point(750, 200)
        Dim pointA As New Point(100, 230)
        Dim pointB As New Point(750, 230)
        e.Graphics.DrawString("Contact List", HeaderFont, Brushes.Black, 310, 100)
        e.Graphics.DrawString("Report", HeaderFont, Brushes.Black, 350, 150)
        e.Graphics.DrawRectangle(Pens.Black, e.MarginBounds)
        e.Graphics.DrawLine(Pens.Black, point1, point2)
        e.Graphics.DrawLine(Pens.Black, pointA, pointB)
        e.Graphics.DrawString("FirstName", BodyFont, Brushes.Black, 100, 200)
        e.Graphics.DrawString("LastName", BodyFont, Brushes.Black, 250, 200)
        e.Graphics.DrawString("City", BodyFont, Brushes.Black, 400, 200)
        e.Graphics.DrawString("State", BodyFont, Brushes.Black, 530, 200)
        e.Graphics.DrawString("Email", BodyFont, Brushes.Black, 670, 200)
    End Sub


    Private Sub frmPrint_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Dim con As New clsInfo
        'con.Connectionstring = mdlGlobal.strConnection
        'con.SQL = "SELECT ID, LastName, FirstName, Address, City, State, ZipCode, Telephone, Cellphone, Email, Birthdate FROM tblContactInfo" _
        '& " ORDER BY LastName, FirstName"

        'con.da.Fill(con.ds, "MyTable")
        'DataGridView1.DataSource = con.ds.Tables("MyTable").DefaultView

        PrintPreviewControl1.Document = PrintDocument1

    End Sub


End Class


That displays this but I dont know how to further load the data from the table onto the report.
Posted Image
But If I use the datagridview I only get a portion on the screen. Where am I going wrong?
Posted Image

Is This A Good Question/Topic? 0
  • +

Page 1 of 1