הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, December 19, 2015 3:07 PM
I would like to make an example of how to print an RDLC report for questions that keep coming up about it. I understand how to print but I dont understand reports and databases etc. I just want to make a simple RDLC report to print my example from a simple DataTable.
I can make the data table but then I get lost on how to make the report. I tried the report wizard but could not define the dataset using the datatable and its fields etc. However I dont want to use the wizard I want to generate the report in code only from a datatable with like 4 rows and 3 cols.
Can someone show a simple code example of making a report from a datatable of simple strings like name, grade. Or whatever data.
I will be printing to 8.5 x 11 with 1 in margins (or whatever) so the report should be that size. I will be printing using this method of capturing an emf file. I just need the report first.
PS If a data table is not the way then I am open to any method to make a report, from RDLC or similar (xml??) that I can put in an example post on the forum. I cant easily show an example that uses data from a monster sql database or whatever. I just need a simple example report made in code by whatever method.
All replies (11)
Monday, December 21, 2015 7:25 AM ✅Answered | 1 vote
There is an example in the below link that shows a sample RDLC report, don't skip the wizard when creating your report as this is made to help you define the initial design and you can customize later.
1- If you want to add a report in the above sample, Right click on the project > Add new Item > Report Wizard.
2- Put a Name for your DataSet, and select the Customers as DataSource and in Available DataSet DataTable1, and of course you can create another DataSet and add the DataTable you want to use for your report.
3- In the next screen drag the columns to Values list and you can try different scenarios there and click next to see a preview. For example if you want to apply grouping you can add column to Row groups list...
The sample is connecting to SQL DB for pulling data, but you can also populate your DT via Code as below sample:
Private Function GetData() As Customers
Using dsCustomers As New Customers()
dsCustomers.Tables("DataTable1").Rows.Add("1", "Name 1", "City 1", "Country 1")
dsCustomers.Tables("DataTable1").Rows.Add("2", "Name 2", "City 2", "Country 2")
Return dsCustomers
End Using
End Function
Fouad Roumieh
Tuesday, December 22, 2015 2:46 PM
Thanks Fouad.
I looked through that it seems quite good instructions although I go side tracked and have not worked it out yet.
It still seems quite complicated. I was hoping for something simple for a simple printing example but maybe it is not simple.
:)
Tuesday, December 22, 2015 3:07 PM
It still seems quite complicated. I was hoping for something simple for a simple printing example but maybe it is not simple.
Tommy,
Would it make it easier if you were using a class for the Typed Data rather than a DataTable and DataSet?
I can show you how to get VS to "see" it as though it's a DataTable - I'll explain more if you want.
If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln
Tuesday, December 22, 2015 3:25 PM | 1 vote
Tommy,
If you're interested (maybe for something else if not this), the following shows how to do it. I'm using the wizard here for this which makes it pretty easy:
For all intents, for reading the data (not writing it or saving it), this may as well be a DataTable from a Database.
If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln
Tuesday, December 22, 2015 3:31 PM
It still seems quite complicated. I was hoping for something simple for a simple printing example but maybe it is not simple.
Tommy,
Would it make it easier if you were using a class for the Typed Data rather than a DataTable and DataSet?
I can show you how to get VS to "see" it as though it's a DataTable - I'll explain more if you want.
If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln
Frank,
I don't really know if it would be "easier."
I was just going to make a simple example of how to print an RDLC report without my needing to learn what RDLC really is. I know how to do the printing if I have a report (report viewer report). For a simple example I just need a simple RDLC report to use. I need to generate it or something in the example. I don't care what it is. I just want it to be less than 50 lines of code so it can be posted easily. I just want to show easy code to print the report. Not how to make an RDLC report.
I think maybe the answer is just to post the RDLC itself which I think is a text file similar to xml. So I could just show that text in the forum post and the user would just have to copy the text file from the forum post, save it, and then example code would read it and print it.
Its not a big thing. Not sure I am even going to do any more with it at this time.
Tuesday, December 22, 2015 4:06 PM
Frank,
I don't really know if it would be "easier."
I was just going to make a simple example of how to print an RDLC report without my needing to learn what RDLC really is. I know how to do the printing if I have a report (report viewer report). For a simple example I just need a simple RDLC report to use. I need to generate it or something in the example. I don't care what it is. I just want it to be less than 50 lines of code so it can be posted easily. I just want to show easy code to print the report. Not how to make an RDLC report.
I think maybe the answer is just to post the RDLC itself which I think is a text file similar to xml. So I could just show that text in the forum post and the user would just have to copy the text file from the forum post, save it, and then example code would read it and print it.
Its not a big thing. Not sure I am even going to do any more with it at this time.
Well obviously I botched this - I don't know why the last name isn't showing up, but this will still let you experiment with it:
Do you want me to upload this project for you to try out and get whatever you want from it?
What did you mean by "post the RDLC itself"? How would I do that for this?
If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln
Tuesday, December 22, 2015 4:46 PM
Thanks Fouad.
I looked through that it seems quite good instructions although I go side tracked and have not worked it out yet.
It still seems quite complicated. I was hoping for something simple for a simple printing example but maybe it is not simple.
:)
It would be better I think if you drop here a screenshot of your final report design with some dummy data inside, you can do a template in Excel then we can compile a VB project for you to use as is or to import its files to your existing project.
Its simple what I've posted but not sure what went wrong on your side.
Fouad Roumieh
Tuesday, December 22, 2015 4:47 PM
BTW do you have the Report Viewer Controls in your VS?
Fouad Roumieh
Tuesday, December 22, 2015 5:27 PM
BTW do you have the Report Viewer Controls in your VS?
Fouad Roumieh
Well I don't even know. I thought so but I have not gotten that far.
Nothing "went wrong" I just did not work through the whole thing as I got to doing something else.
It is just for a printing example. Therefore I don't want to make the user do anything. Just copy the example to a project and run it to print. Its not about making a report. Its about printing the report. So I wanted to start my example with a report already made (by the example code if easy).
Don't worry about it. Its harder to explain what I was thinking of than to do it maybe. I thought there was an easy way to just make a report from a data table (I sort of understand datatable) but its not that easy, to me, not really knowing the difference between a dataset, a field, or an sql data base.
Thanks again.
Tuesday, December 22, 2015 5:39 PM
Frank,
I don't really know if it would be "easier."
I was just going to make a simple example of how to print an RDLC report without my needing to learn what RDLC really is. I know how to do the printing if I have a report (report viewer report). For a simple example I just need a simple RDLC report to use. I need to generate it or something in the example. I don't care what it is. I just want it to be less than 50 lines of code so it can be posted easily. I just want to show easy code to print the report. Not how to make an RDLC report.
I think maybe the answer is just to post the RDLC itself which I think is a text file similar to xml. So I could just show that text in the forum post and the user would just have to copy the text file from the forum post, save it, and then example code would read it and print it.
Its not a big thing. Not sure I am even going to do any more with it at this time.
Well obviously I botched this - I don't know why the last name isn't showing up, but this will still let you experiment with it:
Do you want me to upload this project for you to try out and get whatever you want from it?
What did you mean by "post the RDLC itself"? How would I do that for this?
If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln
Ok Frank, let me look it over. I am not sure what I am doing, if anything, at this time...
"What did you mean by "post the RDLC itself"?
From my limited reading it seems I saw mentions that RDLC is XML. I sort of assumed there was originally windows RDLC and then it morphed into XML but I could be way wrong.
So again I am assuming XML is a text file when saved? Right? So RDLC can be nothing but an XML text file. But I could be wrong about that.
Thanks.
PS so my example could read the file (posted on the forum about 20 lines) and generate a report and then print it. Must be simple or it looses the whole purpose for making the example. A simple example that can be posted on the forum when folks ask how to print an Rdlc file.
Like how to print a text file. First you need a txt file. Then you can print it. I am trying to make a text file but its an RDLC file (or an RDLC string/report in memory or whatever it is which I am still trying to figure).
Tuesday, December 22, 2015 6:01 PM | 1 vote
Well I don't even know. I thought so but I have not gotten that far.
Nothing "went wrong" I just did not work through the whole thing as I got to doing something else.
Its easy to verify if you have it installed or not, it should be under Reporting tab of the toolbox (if installed, otherwise all the examples we are giving here won't work for you):
And if it is but for some reasons the Reporting tab is hidden, you can right click in the Toolbox panel and click Choose Items and enable as below
If its not installed you can also easily donwload and install, or even install from the control panel but let us know first which VS version you are working with.
There is also an option to print the form if you want, but again I don't know how your final report looks like:
https://www.youtube.com/watch?v=BnvV-gVBw0I
this component is available here:
https://www.microsoft.com/en-us/download/details.aspx?id=25169
Fouad Roumieh