Symptom
Reproducing the Issue
C#
Resolution
How can I add a Database field using the Crystal Reports .NET inproc RAS SDK:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.DataDefModel;
// CR Declarations
ReportDocument boReportDocument;
ISCDReportClientDocument boReportClientDocument;
CrystalDecisions.ReportAppServer.ReportDefModel.Section m_boSection;
CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject m_boFieldObject;
//Create a new ReportDocument
m_boReportDocument = new ReportDocument();
// load the RPT file
m_boReportDocument.Load("..\\..\\DummyReport.rpt");
//Access the ReportClientDocument in the ReportDocument (EROM bridge)
m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
//Get the first section in the details section
m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.DetailArea.Sections[0];
/Create the field object that we will add to the report and set all of its properties
m_boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();
//Set which field to use for the data to be displayed
m_boFieldObject.DataSourceName = "{Customer.City}";
m_boFieldObject.FieldValueType = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
m_boFieldObject.Left = 4 * 1440; //1440 twips per inch
m_boFieldObject.Width = 3 * 1440;
m_boFieldObject.FontColor = new CrystalDecisions.ReportAppServer.ReportDefModel.FontColor();
m_boFieldObject.FontColor.Font.Name = "Arial";
m_boFieldObject.FontColor.Font.Size = 10;
m_boFieldObject.Format.HorizontalAlignment = CrystalDecisions.ReportAppServer.ReportDefModel.CrAlignmentEnum.crAlignmentLeft;
//Add the object to the report
boReportClientDocument.ReportDefController.ReportObjectController.Add(boFieldObject, boSection, -1);
// show in reportviewer
crystalReportViewer1.ReportSource = m_boReportDocument;
Using Crystal Reports XI R2 Service Pack 2 and higher, you can now access the report modification APIs without any additional licensing by using the inprocess-RAS engine through the Crystal Reports .NET SDK. An example of accessing the RAS SDK through the Crystal Reports .NET SDK is as follows:
See Also
Keywords
RAS, Modification, In-Process, .NET, Create, Add, Remove, Change, Modify, ReportClientDocument, inproc, DBField, database field , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To