C#中的Crystal报表需要登录

时间:2012-07-02 06:15:48

标签: c# crystal-reports crystal-reports-2008

我在Visual Studio 2010中编写了以下内容:

    label2.Text = Convert.ToString(BAssistencia.nroo);
    ReportDocument oRep = new ReportDocument();
    ParameterField campo = new ParameterField();
    ParameterFields campo2 = new ParameterFields();
    ParameterDiscreteValue Pdv = new ParameterDiscreteValue();

    campo.Name = "@pedido";
    Pdv.Value = label2.Text;
    campo.CurrentValues.Add(Pdv);
    campo2.Add(campo);
    crystalReportViewer1.ParameterFieldInfo = campo2;
    oRep.Load("C:/Relatorios/CrystalReport3.rpt");
    crystalReportViewer1.ReportSource = oRep;
    oRep.SetDatabaseLogon("sa","password","server","database");

使用Visual Studio在计算机上打开报告,但在部署时,应用程序会一次又一次地请求日志。我究竟做错了什么?提前谢谢。

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

你能试试这段代码吗?

ReportDocument rpt = new ReportDocument();
        rpt.Load(@"C:\CrystalReport1.rpt");

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "SERVERNAME";
        crConnectionInfo.DatabaseName = "DATABASENAME";
        crConnectionInfo.UserID = "USERNAME";
        crConnectionInfo.Password = "PASSWORD";
        crConnectionInfo.IntegratedSecurity = false;

        TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
        TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
        Tables CrTables;
        CrTables = rpt.Database.Tables;

        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in CrTables)
        {
            crTableLogonInfo = crTable.LogOnInfo;
            crTableLogonInfo.ConnectionInfo = crConnectionInfo;
            crTable.ApplyLogOnInfo(crTableLogonInfo);
        }
        crystalReportViewer1.ReportSource = rpt;
        crystalReportViewer1.Refresh();