Did I miss something? (printing a report in C#) RRS feed

  • Question

  • i've been making a windows application written in C# to work around with a database, and things have been going well. i have a series of forms that easily update and modify database entries. however, i've run into a dead end now that i need to provide some functionality for printing some database contents via microsoft reports. basically i use a dataset to fill textboxes and other controls on a report that pertain to a given account number, and i need to print the report for any given series of accounts numbers i choose in the database.


    after trying to find any kind of tutorial to show me how to do this, all i have found is, which hasnt done much for me. this appears to fill a report with data from an XML, which doesnt really work for my purposes. my data is inside an access database. it also looks like the program's code has a lot of unnecessary formatting going on for the report itself, which i dont think i really need. i could be wrong though, after all i dont have a lot of experience with working with microsoft reports.


    on top of that, the code is designed for a console application, and i did what i could to try to make it work with a windows forms application. instead of having the program execute the print sequence on runtime, i trigger it with a command button. it looks like it should work, but i get a visual studio unhandled exception that says "An error occurred during local report processing." 


    all i want to do is have the database fill the report with info from a databse entry, print it, then move on to the next account number, rinse & repeat.

    Friday, February 8, 2008 10:45 PM

All replies

  • That's the great part about examples, sometimes they are right on target, and other times they are so far out in left field they are useless.


    So, let me try to throw the basics at you, and see how it goes.


    First off, you want to use a .RDLC report.  So any searches you do, should be related to that.


    Creating reports is done in a few basic steps.    And if your into books, I recommend Asif Sayed's book "Client-side reporting in C#".


    But let me see if I can steer you in the right direction, because what you want to do sounds very simple.


    A report wants to accept data from you and display it in the format you lay out.  So first you need to decide on the easiest format that you can put the data together in.  


    Personally, I use a dataset designer, and then I drag and drop stored procedures onto that dataset designer.  Once i've setup how my data will look, I can create a report that handles this data.   


    I open the .RDLC to the designer, and on the VS menu bar, click reports, then datasources, and I add my datatable I just created as a datasource.


    Then I whatever controls I want onto the report, most likely a table...but doesn't have to be.  And in the expression editor for each control I add the appropriate field from my data that I want to display in that control.


    Once that's completed, you've got your report all setup.   Now you just need to attach it to a report viewer, and at runtime hand it the proper datasource.  


    And I'm sure my commentary is a bit vague, but here is a link to an article by Asif Sayed that may help.



    Monday, February 11, 2008 3:27 PM
  • i have all that down. i just need to be able to send my report to my printer programmatically so that i can print info from my dataset.

    Tuesday, February 12, 2008 2:49 AM