Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Filling Unbound Fields on a Crystal Report in ASP.NET

Posted on 2006-07-05
Medium Priority
Last Modified: 2010-05-18
I  have  a Crystal Report created with unbound fields.  I want to be able to use ASP.NET to update the crystal report in my code with data from a sql database.

I have never worked with crystal reports before.

I need to know how to:
1 - Access the report in my code.
2 - Update the unbound fields
3 - Save the report as a pdf

I am so frustrated!  Can somebody please please help me?!
Question by:proten
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
LVL 16

Expert Comment

ID: 17047654
My suugestion is to get your data from DB using ASP.NET code and then pass the data into the crysytal report as reprot parameters.

For exporting to PDF, see


Author Comment

ID: 17047775
I can get the data no prob in my ASP.NET code.

I have the fields that I need to use in my report, now what?

How do I access the report in my code and how do I set the parameters to fill the data?
LVL 16

Expert Comment

ID: 17048237
Add a parameter field in the crystal report and then you can drag the parameter field onto your crystal report.

To assign value to the parameter, you can refer

Hope that helps

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 17050532
I think I need to fill the fields dynamically in the background.

I'll explain my scenario:

I am creating a packing slip/s.  When a user enters say a customer number and some other information on the front end, I will validate the info and then populate one or more of the template I have in my report.  I will be getting the data from 3 different tables and one will be repetitive.

Address Info is one record on the address table
Customer Id info is one record on the cust table
Order Info is multiple records on the order table (I display these as a list)

I will create one packing slip per customer but there may be a few customers.  

The end result is a report with 1 or more pages.  Each page containing the information for one customers order that may contain many items.

The way I figured I'd do it is create an screen that has input fields for the key information.  Then in the code-behind I can get the data from the db and manipulate it and in my code set each field to an unbound field in the crystal report that will be generated in my code.  I already have the crystal report template created so I want to "read" it and fill in the "blanks" in my program.

Author Comment

ID: 17050550
I guess my question is that I already have the template created and set out in a .rpt file, how do I read it in my program and fill the fields?
LVL 16

Expert Comment

ID: 17051342
It seems to me you are finding a way to assign a value to a field inside the crystal report from outside.  I doubt if it is possible!?

I hope I understand your scenario correctly.  You generate the packing slip probabaly based on an order which contains customer Id and other items ordered.  Then I will pass just the order Id to the crystal report and then draw the necessary data from DB by the code (actually a DB query) inside crystal report.

Alternatively, you can compose a dataset in ASP.NET which contains all the necessary data of your packing slip and then pass the whole dataset to the crystal report as datasource.


Author Comment

ID: 17052526
I dont think the first option will work because the top portion of the form is regular table data (one record per form) but included on the form is a detail table of up to 10 items per form that is one record per line from one datatable.

The second option makes more sense.  I can create a dataset and name each of the detail lines a different field name.  

I still dont know how to open the file with the template in my code and set the dataset as the datasource for the crystal report.  Also, will I be able to create multiple pages of the same template (i.e. 5 packing slips for different customers)?
LVL 16

Expert Comment

ID: 17055475
The first option is feasible when you use grouping in crystal report.

You have to select all related tables in the crystal report and then use the orderId parameter as the selection criteria.
Group the record by the orderId field and then put the customer name, address stuff in the group header section and put the order lines (item code, qty, etc) in the details section.  (Actually you can choose not using grouping and simply put the cusotmer data in the report header section but I prefer grouping because it allows you to print multiple slips at a time)

For using dataset in CR, please refer to these articales

For having multiple copies of a report, you can create a crystal report and then add the template as multiple subreports.


Author Comment

ID: 17074194
Hope you had a nice weekend.

Okay, I have figured out how to
open the report using rpt.load()
access and set the fields using cr.DataDefinition.FormulaFields("FldName")
and save it to pdf using cr.ExportToDisk()

So now I can create a report with one page.  Now I need to create multiples of the same page in the same document.

Subreport sounds like the right idea.  How do I create and add those to a report?  I want to have one or many of the same page but with different data on each, saved to one pdf file.

Also, I really dont need to save the pdf file to disc, I just need to open it in a pdf viewer so the user can print.  Is there a way to just open the file without saving it?  


Author Comment

ID: 17075763
Another thing,

I did not understood your explanation of grouping.  How does it work and how do I use it?  Can you give me an example?
LVL 16

Expert Comment

ID: 17151019
Sorry for the late reply because I was on vacation last week.

Grouping is a basic function in all reporting tools (including Crystal report) and you can find many tutorials on that.  Here is one I found from internet.

In your case, you can link all your tables (address, customer, order) and pass to the report and then group by OrderID.  Then put data such as customer name, order number, order date, etc in the group header.  The item ordered and qty can be put in the details section.

Hope that helps

Author Comment

ID: 17154011
I finally got it to work, I did the following:

I created 2 crystal reports.
1 - Detail report linking to the datatable containing the detail records for the packing slip.
2 - A main report linking to the datatable with the header information.  I included the detail report as a subreport.

- Grouped the main report by order number so that there would be one page per order.
- Did not use the group headers at all, in fact suppressed them from displaying.  
- Placed the header info in the page header.
- Checked the "New Page After" option for the group footer in the section expert window so that  a new page was generated for each order
- Created a subreport link linking the order number of the detail items to the main page order number so only the details for that order would be generated on that page.

Accessing the report in my code:
- Added the crystal reports references.
- Included the following imports in my code
  Imports CrystalDecisions.CrystalReports.Engine
  Imports CrystalDecisions.Shared
- Open doc in the code:
   Dim cr As New ReportDocument
   cr.Load(Server.MapPath(FileRptName), OpenReportMethod.OpenReportByTempCopy)
- Set data for the report:
   Dim crSub As ReportDocument
   crSub = cr.OpenSubreport(FileSubRptName)
- Open report without saving it:
    Dim crDFDO As New DiskFileDestinationOptions
    crDFDO.DiskFileName = Server.MapPath(FileTempSaveName)
    With cr.ExportOptions
           .DestinationOptions = crDFDO
           .ExportDestinationType = ExportDestinationType.DiskFile
           .ExportFormatType = ExportFormatType.PortableDocFormat
     End With
     Response.ContentType = "application/pdf"

Accepted Solution

ee_ai_construct earned 0 total points
ID: 17356285
PAQ / No Refund
ee ai construct, community support moderator

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question