Question

I have an app that will print every data that is inside of the textboxes. So it means that I don't have database

I use a RDLC to fulfill the printing process. I set up parameters per textbox to my report and add this code so that the textboxes' text will be transferred to the report.

  ReportParameter textbox1param = new ReportParameter("textbox1", textbox1.Text);
  printform.reportViewer1.LocalReport.SetParameters(textbox1param);

My problem though is when I do this way, it makes my system crash while printing because I repeat this code many times just to transfer every textboxes' text in my form. (I repeat the code 10 times only changing the textbox's name and the parameter name.)

I see that there is another method which is using dataset. My problem is I don't use a database because I just print what it is in the screen that the user inputted. So I can't create a query for it. Is there any other way for me to solve this dilemma? Thank you guys!

Was it helpful?

Solution

I've just tried to do a report sample without adding a datasource to the report and it works fine for me. even it it's a bit strange to create a report with no datasource. Here is what I did, I first created a dummy report with 3 parameter, and assing it to the report viewer

enter image description here

After that I went do some coding, for what you're looking for it should not be that complicated, here I show you my code snippet, to populate the parameter I call a function but this is not necessary. If the report doesnt work it could be because you misspelled the parameter name (they are case sensitive!)

private void Form2_Load(object sender, EventArgs e)
{
     reportViewer1.LocalReport.SetParameters(SetParameter());
     reportViewer1.RefreshReport();
}

private static IEnumerable<ReportParameter> SetParameter()
{
     return new List<ReportParameter>
     {
         new ReportParameter("Param1", "text1", false),
         new ReportParameter("Param2", "text2", false),
         new ReportParameter("Param3", "text3", false)
     };
 }

After doing that and running my little sample this is the output, I'm not sure of what went wrong on your report. But as I said before I would check if the parameter names are written as you declared them on the rdlc

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top