2012-07-02 87 views
0

我寫在Visual Studio 2010中的以下內容:Crystal報表需要登錄

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的罰款,但是當我部署,應用程序再次請求日誌然後再次。我究竟做錯了什麼?提前致謝。

回答

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(); 
+0

根據它的要求更改它,也將爲你工作 – Asif

+0

謝謝,但從哪裏來crTable ???我不知道crtable在哪裏創建。 Crtables = rpt.database.tables存在但crtable?我認爲這個代碼可能工作。 –

+0

@alejandro crTable是CrystalDecisions.CrystalReports.Engine.Table的數據表。就像你經常在C#中使用的foreach(DataRow dr in dt.Rows)一樣。你可以使用任何你喜歡的crTable的名字。我試過這段代碼,它工作正常。 – Asif