C#.NET Crystal Report Technology

How to change Formula Field Variables in Crystal Report Programmatically

Open the crystal report you have just created in your project, and from the Field Explorer -> Formula Fields, right click and create Two new Formula Field Variables, lets name it as “parameter1” and “parameter2” respectively. Then drag and drop inside the Crystal Report and place it anywhere according to your need.

Then, use the below code (assume if we need to pass “Hello” & “How are you?” during runtime)


ReportDocument ReportDoc = new ReportDocument();
ReportDoc.Load(Server.MapPath(“~”) + “\CrystalReport1.rpt”);

List paramList = List();
paramList.Add(“Hello”);
paramList.Add(“How are you?”);

for (int i = 1; i < 2; i++)
           if (ReportDoc.DataDefinition.FormulaFields[i-1].FormulaName 
                                                                           == “{” + “@parameter” + i + “}”)
                      ReportDoc.DataDefinition.FormulaFields[i-1].Text 

                                                                                    = “”” + paramList[i-1] + “””;

Spread the love
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments