Skip to navigation
Real World Computing

Automated printing of SQL Server Reports

Posted on 12 Jan 2010 at 15:13

Simon Jones wrestles with the printing of SQL Server Reporting Services Reports

The hardest part in implementing this solution was to generalise my new ServerReportPrintDocument class so that it would work with whichever report, and with whatever parameters, was to be printed. I got around this by making the class take a parameter that was a Delegate to (the address of) a method in my main application. A Delegate is just a Sub or Function definition with no body code of its own: you then define any number of other Subs or Functions that conform to the definition of this Delegate by having the same number and type of parameters, in the same order.

You can then pass the address of one of these Subs or Functions to any other Sub or Function that accepts a parameter of the Delegate type, to provide it with its run-time action. So I could create a new instance of this class, and then pass it the address of a method it should call to fill its particular report.

The class exposes just one property, a standard PrintDocument, which has its own Print method or else can be passed to a PrintPreview window to be shown to the user. Just one extra important feature was required, and that was to make my class implement the IDisposable interface so that it would tidy up when it was no longer required by disposing of its PrintDocument, its list of MemoryStreams and its ReportViewer.

If it didn’t do this properly these objects would hang around for longer than necessary, taking up memory and slowing the computer down (or worse).

1 2
Subscribe to PC Pro magazine. We'll give you 3 issues for £1 plus a free gift - click here

From around the web

Be the first to comment this article

You need to Login or Register to comment.

(optional)

Simon Jones

Simon Jones

Simon is a contributing editor to PC Pro. He's an independent IT consultant specialising in Microsoft Office, Visual Basic and SQL Server.

Read more More by Simon Jones

advertisement

Latest Real World Computing
Latest Blog Posts Subscribe to our RSS Feeds
Latest News Stories Subscribe to our RSS Feeds
Latest ReviewsSubscribe to our RSS Feeds

advertisement

Sponsored Links
 
SEARCH
SIGN UP

Your email:

Your password:

remember me

advertisement


Hitwise Top 10 Website 2010
 
 

PCPro-Computing in the Real World Printed from www.pcpro.co.uk

Register to receive our regular email newsletter at http://www.pcpro.co.uk/registration.

The newsletter contains links to our latest PC news, product reviews, features and how-to guides, plus special offers and competitions.