cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Getting commandtext for the subreport

former_member730353
Participant
0 Likes
889

Report with Command object:

Debugger Output:

Problem:

We are using CR .NET dll version 13.0.29.

We have a Report with command object, and we can get the SQL Query(CommandText) using following code ( Code_block_1). It works fine for the main report. This same report also contains subreport which contain Command Object, but we are not able to get the SQL Query(CommandText) for the subreport using below code(Code_block_1).

But As per the debugger output (please refer the attached image), we are able to see the CommandText. To get the commandtext for the Subreport, we are using code_block_2. And we could get the commandtext for subreport. Is it a right approach to get the commandtext for the subreport using code_block_2. Please confirm.

Requirement:

Is it a right approach to get the commandtext for the subreport using code_block_2. Please confirm.

Pseudo Code:

Code_block_1:

CrystalDecisions.ReportAppServer.DataDefModel.CommandTable
boCommandTable;boCommandTable =
(CrystalDecisions.ReportAppServer.DataDefModel.CommandTable)reportDoc.ReportClientDocument.Database.Tables[0];

ReportSQLQuery = boCommandTable.CommandText;

Code_block_2:

PropertyInfo pi =
subReportDocument.Database.Tables.GetType().GetProperty("RasTables",
BindingFlags.NonPublic | BindingFlags.Instance);

ReportSQLQuery = ((dynamic)pi.GetValue(subReportDocument.Database.Tables, pi.GetIndexParameters()))[0].CommandText;

Thanks,

Samson

Accepted Solutions (1)

Accepted Solutions (1)

0 Likes

Yes it is...

For more info here's the link to my CR for VS Wiki:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

Note: SP 30 is available now and you should upgrade.

On that page is a Parameter test app with log on code that has more info about subreports.

Don

former_member730353
Participant
0 Likes

Thanks for the info.

0 Likes

This particular piece of code raises an exception here:

if (pi == null) return;
                var ReportSQLQuery = ((dynamic)pi.GetValue(doc.Database.Tables, pi.GetIndexParameters()))[0]
                    .CommandText;
Exception is:
This value is write-only.

So it would seem the example needs review? I just need to document the Command object sql - nothing more... The code at the link seems to be more worried about parameters and what not...

That being said, your contributions here, Don, are legendary and very helpful!! Thank you.

0 Likes

Of course, I have no clue where the variable ReportQuery was defined. Maybe it is in fact a report document attribute?

Answers (0)