C# Crystal 报告连接信息和参数

C# Crystal Reports ConnectionInfo and Parameters

我有一个 c# 应用程序,它将某些参数传递给 Crystal 报告,然后加载该报告。这一切都按预期工作,但我现在要求应用程序 运行 针对不同的数据库,而不是本地数据库。

我已经为报告添加了连接信息,但是在加载报告时它现在提示输入报告参数。如果我 运行 针对本地数据库使用相同的代码(包含连接信息),它 运行 是正确的(没有参数提示。这是我的代码:

        public frmReport(ReportDocument cryRpt, DateTime dFromDate, DateTime dToDate,
        Int32 iEmployeeId, Int32 iRetentionDays, 
        Boolean bExTax, Boolean bShowDefinitions, DBase _oDbase, Log _oLog)
    {
        InitializeComponent();

        _oDBase = _oDbase;

        iEmployeeIdReport = iEmployeeId;

        TableLogOnInfos crtablelogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtablelogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;

        string sWowPath = Wow6432Path();

        crConnectionInfo.ServerName = Registry.LocalMachine.OpenSubKey(@"Software" + sWowPath + "\ShortCuts\Database\ShortcutsPOS").GetValue("Server").ToString(); ;
        crConnectionInfo.DatabaseName = Registry.LocalMachine.OpenSubKey(@"Software" + sWowPath + "\ShortCuts\Database\ShortcutsPOS").GetValue("Database").ToString(); ;
        crConnectionInfo.UserID = Properties.Settings.Default.Username.ToString();
        crConnectionInfo.Password = Properties.Settings.Default.Password.ToString();

        CrTables = cryRpt.Database.Tables;

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


        ParameterFields myParams = new ParameterFields();
        ParameterField paramFieldFrom = new ParameterField();
        ParameterField paramFieldTo = new ParameterField();
        ParameterField paramFieldEmployeeId = new ParameterField();
        ParameterField paramFieldRetentionDays = new ParameterField();
        ParameterField paramFieldExTax = new ParameterField();
        ParameterField paramFieldShowDefinitions = new ParameterField();

        ParameterDiscreteValue paramDiscreteValueFrom = new ParameterDiscreteValue();           
        ParameterDiscreteValue paramDiscreteValueTo = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteEmployeeId = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteValueRetentionDays = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteValueEmployeeLevelList = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteValueExTax = new ParameterDiscreteValue();
        ParameterDiscreteValue paramDiscreteValueShowDefinitions = new ParameterDiscreteValue();

        paramFieldFrom.Name = "FromDate";
        paramFieldTo.Name = "ToDate";
        paramFieldEmployeeId.Name = "EmployeeId";
        paramFieldRetentionDays.Name = "RetentionDays";
        paramFieldExTax.Name = "ExTax";
        paramFieldShowDefinitions.Name = "ShowDefinitions";

        paramDiscreteValueFrom.Value = dFromDate;                       
        paramDiscreteValueTo.Value = dToDate;
        paramDiscreteEmployeeId.Value = iEmployeeId;
        paramDiscreteValueRetentionDays.Value = iRetentionDays;
        paramDiscreteValueExTax.Value = bExTax;
        paramDiscreteValueShowDefinitions.Value = bShowDefinitions;

        paramFieldFrom.CurrentValues.Add(paramDiscreteValueFrom);
        paramFieldTo.CurrentValues.Add(paramDiscreteValueTo);
        paramFieldEmployeeId.CurrentValues.Add(paramDiscreteEmployeeId);
        paramFieldRetentionDays.CurrentValues.Add(paramDiscreteValueRetentionDays);
        paramFieldExTax.CurrentValues.Add(paramDiscreteValueExTax);
        paramFieldShowDefinitions.CurrentValues.Add(paramDiscreteValueShowDefinitions);

        myParams.Add(paramFieldFrom);
        myParams.Add(paramFieldTo);
        myParams.Add(paramFieldEmployeeId);
        myParams.Add(paramFieldRetentionDays);
        myParams.Add(paramFieldExTax);
        myParams.Add(paramFieldShowDefinitions);

        cryViewer.ParameterFieldInfo = myParams;

        cryViewer.Refresh();

        cryViewer.ReportSource = cryRpt;
    }

我要补充一点,报告位置是从另一个表单传递给这个方法的,然后在这个 return 上 .Show() 是 运行。

编辑:好的,只是 运行 一些更多的测试,如果我的连接是 machinename\dbinstance 它也不起作用,但它适用于 (local)\instancename。报告文件中的命令对象有一个连接集(local)\instancename,是这个问题吗?

在这种情况下,我的子报告有自己的命令对象,这就是问题所在。我已经更改了报告,因此子报告不再存在(非常基本并且不需要分开)并且问题停止了。