on 2025 Feb 07 5:32 PM
private CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument1;
private CrystalDecisions.Windows.Forms.CrystalReportViewer uC_Stampa1;
//create a report document and load a report .rpt
reportDocument1.Load("xxxxx.rpt");
//set selection formula
reportDocument1.RecordSelectionFormula = "sSelectionFormula";
//set reportsource of CrystalReportViewer with reportdocument
uC_Stampa1.ReportSource = reportDocument1;
//Selection formula of CrystalReportViewer is blank . Why?
//How can I set the formula for CrystalReportViewer
uC_Stampa1.SelectionFormula --> is blank .
Reference:
CrystalDecisions.CrystalReports.Engine ver 13.0.4000.0
VS2019
Request clarification before answering.
First 13.0.4000.0 is the framework, look in Programs and Features for Cr for VS and the SP installed.
You are kind of vague but try setting the log on info before setting the record selection formula, it can make a difference since the database SQL is dynamic based on the Client used.
Dumb question but does the report you are opening have one?
I tried it both using the Engine and RAS, putting it into a text box:
btnRecordSelectionForm.Text += "\nDon Report Selection Forrmula" + rpt.RecordSelectionFormula.ToString() + "\n";
// Record selection formula with comments included can only be retrieve via RAS
//rpt.RecordSelectionFormula = "if not isnull({CUSTOMER.Customer Credit ID}) then {CUSTOMER.Customer Credit ID} = {%test} else true";
CrystalDecisions.ReportAppServer.DataDefModel.ISCRFilter myRecordSelectionWithComments; // = new CrystalDecisions.ReportAppServer.DataDefModel.;
myRecordSelectionWithComments = rptClientDoc.DataDefController.DataDefinition.RecordFilter;
if (myRecordSelectionWithComments.FreeEditingText != null)
{
//myRecordSelectionWithComments.FreeEditingText = rptClientDoc.DataDefController.RecordFilterController.GetFormulaText();
btnRecordSelectionForm.Text += "\nWith Comments:\n" + myRecordSelectionWithComments.FreeEditingText.ToString();
btnRecordSelectionForm.Update();
btnRecordSelectionForm.AppendText("\n\n");
btnRecordSelectionForm.Update();
btnRecordSelectionForm.AppendText("\n\nWithout Comments:\n" + rpt.RecordSelectionFormula.ToString());
btnRecordSelectionForm.Update();
//myRecordSelectionWithComments.FreeEditingText = "{TStat.TArt_Cod} = \"A823/001\"";
//rpt.RecordSelectionFormula = "{TStat.TArt_Cod} = \"A823/001\"";
//IsRpt = false;
}
else
btnRecordSelectionForm.Text = "No Record Selection formula";
Works fine for me.
Single step through your code and verify your report is loading etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply but i not fix the issue
The componet installed is:
SAP Crystal Reports for Visual Studio (SP37) 32b installation package for Microsoft Visual Studio IDE (VS 2019 and below)
CRforVS13SP37_0-80007712.EXE
I use Vs2019
This is my code:
(with the old version of Crystal Report has always worked)
reportDocument1 = new ReportDocument();
reportDocument1.Load(sNomeReport);
//Set Logon
bInErr = !clsReport.OnLogon(uC_Stampa1, reportDocument1, sCredenziali_UserID, sCredenziali_Password, sCredenziali_SQLServer, sCredenziali_Database);
reportDocument1.RecordSelectionFormula = sSelectionFormula;
uC_Stampa1.ReportSource = reportDocument1;
--> in this point uC_Stampa1.SelectionFormula is blank , with old version of CR Selectionformula if filled.
// i have add this code
string app;
string app1;
ISCDReportClientDocument rptClientDoc = (ISCDReportClientDocument)reportDocument1.ReportClientDocument;
CrystalDecisions.ReportAppServer.DataDefModel.ISCRFilter myRecordSelectionWithComments;
myRecordSelectionWithComments = rptClientDoc.DataDefController.DataDefinition.RecordFilter;
if (myRecordSelectionWithComments.FreeEditingText != null)
{
//myRecordSelectionWithComments.FreeEditingText = rptClientDoc.DataDefController.RecordFilterController.GetFormulaText();
app = "\nWith Comments:\n" + myRecordSelectionWithComments.FreeEditingText.ToString();
app1= reportDocument1.RecordSelectionFormula.ToString();
//app and app1 is correct and is setted = "{vwDocumenti.TDoc_Codice}=7881";
}
// in this point uC_Stampa1.SelectionFormula is blank
//for fix the issue, I added this line, but I don't know if it's correct .Without this line the report is not filtered
uC_Stampa1.SelectionFormula = reportDocument1.RecordSelectionFormula
User | Count |
---|---|
66 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.