cancel
Showing results for 
Search instead for 
Did you mean: 

AccessViolationException when deleting field object from subreport

Former Member
0 Kudos

Hi,

We have been working on Crystal Reports(using Interop.CRAXDRT.dll V11.5.0). For some reason we need to replace the ReportObjects(FieldObjects, TextObject etc) from reports. We are successfully able to replace the field objects from main report, however if we try to delete the field objects from subreport we were getting access violation exception,

For generating subreport object we had written following code.


foreach (Section section in objRpt.Sections)

            {

                foreach (var rptObjects in section.ReportObjects)

                {

                    var subReportObj = rptObjects as SubreportObject;

                    if (subReportObj == null) continue;

                    var subReport = objRpt.OpenSubreport(subReportObj.SubreportName);

                    subReport.Database.LogOnServerEx("crdb_ado.dll", _mSDsn, "", _mSUid, _mSPwd, "OLE DB", _sConnectString);

                    //Traverse the report and collect the field objects to delete.

                }

            }

And following is the code to delete the field object.


  var rptSection = objReport.Sections.Cast<Section>().FirstOrDefault(section => section.Name.Equals("DetailsSection1", System.StringComparison.OrdinalIgnoreCase));

if(rptSection ==null) return;

var oldFieldObject = rptSection.ReportObjects.OfType<FieldObject>().FirstOrDefault(fieldObj =>(fieldObj.Field is DatabaseFieldDefinition) && fieldObj.Name.Equals("Email1",System.StringComparison.OrdinalIgnoreCase));

if (oldFieldObject == null) return;

rptSection.DeleteObject(oldFieldObject);

and last line of above code is giving following error.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

As CR XI R2 is no longer supported I moved your post to the SAP Crystal Reports - Legacy SDKs SCN Space.

Please see if this KBA will help:

1332327 - Object doesn't support this property or method when using Section.DeleteObject method in R...

And the Developer Help file for CR XI R2 is here:

Developer Library XI Release 2 Productivity Pack

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Message was edited by: Ludek Uher

Answers (0)