cancel
Showing results for 
Search instead for 
Did you mean: 

RE: What's database field are used in crystal report file?

Former Member
0 Kudos

Hi all

Please help me a C# code that using Crystall Report API (Crystal Report XI- Develop license) to get the list of database fieldname that using in crystal Report file. (What's database field using in header section ,group section , detail section of report.....)

We looking forward to hearing from you

Thanks

Son

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Son,

please use this code below to get a list of used database fields in a report :

//********************************************************************

//File Name: CS_Get_report_data_out_inproc.sln

//Created: April 11, 2008

//Author ID: FLI

//

//Purpose: This C# .NET sample Windows application demonstrates

// how to retrieve report data and put the into a XML file

// using unmanaged RAS.

//

// Note this is available without a dedicated RAS with SP2 for XI R2

//********************************************************************

using System;

using System.IO;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.ReportAppServer.ClientDoc;

using CrystalDecisions.ReportAppServer.Controllers;

using CrystalDecisions.ReportAppServer.DataDefModel;

namespace CS_Get_report_data_out_inproc

{

public partial class Form1 : Form

{

// CR Declarations

ReportDocument boReportDocument;

ISCDReportClientDocument boReportClientDocument;

public Form1()

{

InitializeComponent();

//Create a new ReportDocument

boReportDocument = new ReportDocument();

// load the RPT file

boReportDocument.Load("..
..
ReportData.rpt");

// show in reportviewer

crystalReportViewer1.ReportSource = boReportDocument;

}

private void button1_Click(object sender, EventArgs e)

{

//Access the ReportClientDocument in the ReportDocument (EROM bridge)

boReportClientDocument = boReportDocument.ReportClientDocument;

// Retrieve the Rowset Controller

RowsetController boRowsetController = boReportClientDocument.RowsetController;

// Retrieve the metadata (column headers) - this allows you to only retrieve the data that is on the report.

RowsetMetaData boRowsetMetaData = new RowsetMetaData();

Fields boFields = boReportClientDocument.DataDefinition.ResultFields;

boRowsetMetaData.DataFields = boFields;

// Now print out the data in XML file

//(Note: This will print out the results of formulas too)

StreamWriter sw = new StreamWriter("C:
ReportData.xml", false);

sw.WriteLine("<?xml version='1.0' encoding='utf-8'?>");

sw.WriteLine("<ReportData>");

sw.WriteLine("<Reportheader>");

// Print out the titles

for (int i = 0; i < boFields.Count; i++)

{

String boFieldName = boFields<i>.Name;

sw.WriteLine("<ReportheaderDetail>" + boFieldName + "</ReportheaderDetail>");

}

sw.WriteLine("</Reportheader>");

//Create the cursor which lets us loop through the data

RowsetCursor boRowsetCursor = boRowsetController.CreateCursor(null, boRowsetMetaData, 1);

Record boRecord;

while (boRowsetCursor.IsEOF == false)

{

sw.WriteLine("<Customer>");

boRecord = boRowsetCursor.CurrentRecord;

for (int j = 0; j < boFields.Count; j++)

{

try

{

sw.WriteLine("<Detail>" + (String)boRecord[j].ToString() + "</Detail>");

}

catch (Exception err)

{

sw.WriteLine("<Error>" + err.Message + "</Error>");

}

}

sw.WriteLine("</Customer>");

boRowsetCursor.MoveNext();

}

sw.WriteLine("</ReportData>");

// CLose the file

sw.Close();

MessageBox.Show("XML File 'ReportData.xml' successfully created on C:");

}

}

}

Answers (0)