cancel
Showing results for 
Search instead for 
Did you mean: 

Programaticaly add Table in CR database fields

Former Member
0 Kudos

Hi to all,

I'm using CR 11.5, Visual Studio 2005-C#,asp.net and SQL server 2005.

My work is during runtime to add the Fieldobjects in

crystal report now i can do it but during design time i added

the Table in Crystal Report ->FieldObjects>Database Fields

by that programaticaly i can add the Fieldobjects.

What i try to do is

to add the table to CR Database fields by programaticaly.

Is this possible then experts please help me.

Thanks in advance

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

this is a good code

Former Member
0 Kudos

I found a way like this

private void AddTableFromDataSet(ref CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, System.Data.DataSet ds)

{

ISCDReportClientDocument rasReport = rpt.ReportClientDocument;

// Convert the DataSet to an ISCRDataset object (something the ISCDReportClientDocument can understand)

CrystalDecisions.ReportAppServer.DataDefModel.ISCRDataSet rasDS;

rasDS = CrystalDecisions.ReportAppServer.DataSetConversion.DataSetConverter.Convert(ds);

// Add the dataset as a data source to the report

rasReport.DatabaseController.AddDataSource((object)rasDS);

// Add a field to the report canvas

// Note: This is quick and dirty. No positioning, resizing, formatting, etc.

CrystalDecisions.ReportAppServer.Controllers.ISCRResultFieldController rfc;

CrystalDecisions.ReportAppServer.DataDefModel.ISCRTable crTable;

CrystalDecisions.ReportAppServer.DataDefModel.ISCRField crField;

rfc = rasReport.DataDefController.ResultFieldController;

crTable = rasReport.Database.Tables[0];

crField = crTable.DataFields[2]; // Hardcoded field "Customer Name" in the Customer table from Xtreme Sample Database

rfc.Add(-1, crField);

// Save the report template to disk (without data)

//object path = @"c:\documents and settings\administrator\desktop\";

//rasReport.SaveAs("test.rpt", ref path, 0);

//MessageBox.Show("Done!");

}