Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My values arent getting pass automatically, any idea why?

On load code:

C#
//login so users wont have to enter user/pass all the time
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

cryRpt.Load(Server.MapPath("~/reports/RecReport.rpt"));

crConnectionInfo.ServerName = "e40";
crConnectionInfo.DatabaseName = " ";
crConnectionInfo.UserID = "usr";
crConnectionInfo.Password = "pas";

CrTables = cryRpt.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

CrystalReportSource1.ReportDocument.SetParameterValue(0, Request.QueryString["PONU"]);
CrystalReportSource1.ReportDocument.SetParameterValue(1, Request.QueryString["MRNU"]);

CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();


It asks me to enter the values again after the code run, am i missing anything?
Posted

You do not need to refresh the Report viewer after setting the report source.
Remove the line
C#
CrystalReportViewer1.RefreshReport();
 
Share this answer
 
Comments
r00n3y 28-Jan-16 20:35pm    
i have tried that and it comes back with perms. prompts
an0ther1 28-Jan-16 21:23pm    
I have about 10 different projects using Crystal Reports (both ASP & Windows Form based) and, admittedly, use a different processing order to you. See new Solution below for additional information.
an0ther1 31-Jan-16 15:22pm    
Actually, sorry I completely missed why you are having the problem.
The below solution should work correctly but I think the problem is where you have;
CrystalReportSource1.ReportDocument.SetParameterValue...
Set the Report parameters using as below;
cryRpt.SetParameterValue...

Kind Regards
The way I load a report is as follows - this always works for me regardless if the parameters are Crystal or due to an underlying stored procedure;

C#
using(ReportDocument crReport = new ReportDocument())
{
    crReport.Load("Path and file name");
    if(crReport.DataDefintion.ParameterFields.Count > 0)
    {
        foreach(ParameterFieldDefintion crDef in crReport.DataDefinition.ParameterFields)
        {
            // check the parameter is not in a Sub Report
            if(crDef.ReportName == string.Empty)
            {
                crReport.SetParameterValue(crDef.ParameterFieldName, "myvalue");
            }
        }
    }
    ConnectionInfo crConn = new ConnectionInfo();
    crConn.ServerName = "myServer";
    crConn.DatabaseName = "myDbName";
    crConn.UserID = "myUserName";
    crConn.Password = "myPassword";
    Tables crTables = crReport.Database.Tables;
    // I have had problems using the tables collection so instead I use an enumerator
    for(int i = 0; i < crTables.Count; i++)
    {
        Table crTable = crTables[i];
        TableLogOnInfo tblInfo = crTable.LogOnInfo;
        tblInfo.ConnectionInfo = crConn;
        crTable.ApplyLogOnInfo(tblInfo);
    }
    if(crReport.Subreports.Count > 0)
    {
        for(int i = 0; i < crReports.Subreports.Count; i++)
        {
            using(ReportDocument crSub = crReport.OpenSubReport(crReport.Subreports[i].Name)
            {
                Tables crSubTables = crSub.Database.Tables;
                for (int ii = 0; ii < crSubTables.Count; ii++)
                {
                    Table crSubTable = crSubTables[i];
                    TableLogOnInfo tblSInfo = crSubTable.LogOnInfo;
                    tblSInfo.ConnectionInfo = crConn;
                    crSubTable.ApplyLogOnInfo(tblSInfo);
                }
                crSub.Close();
            }
        }
    }
}
this.crystalReportViewMain.ReportSource = crReport;
// this.crystalReportViewMain.RefreshReport();


If I uncomment the last line I get the behavior you describe in that the Report then prompts me to re-enter the parameter values

Really hope this helps you

Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900