2010-08-10 67 views
1

所以我有一個.rpt文件,並希望在Web窗體中顯示水晶報告。在asp.net中的水晶報告(我有一個.rpt文件)

我將報表查看器拖到我的Web表單上,並在設計時設置了它的CrystalReportSource。

當我眉頭頁面,它要求我輸入的SQL密碼,並已填補了SQL服務器名稱和用戶

我怎麼可以在代碼中設置數據庫連接背後,讓頁面顯示報告沒有提示輸入SQL密碼?

我應該只是生成一個數據集並將晶體報告查看器綁定到rpt文件和我的數據集?

+0

這就是我通常所做的。創建一個連接,獲取數據,綁定到報告,顯示它。 – 2010-08-10 19:28:19

回答

1
using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using CrystalDecisions.CrystalReports.Engine; 
using CrystalDecisions.Shared; 


public partial class crystal_report : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    private void Page_Init(object sender, EventArgs e) 
    { 
     ConfigureCrystalReports(); 
    } 

    private void ConfigureCrystalReports() 
    { 

     ConnectionInfo connectionInfo = new ConnectionInfo(); 
     connectionInfo.DatabaseName = "PMIS"; 
     connectionInfo.UserID = "PMIS_User"; 
     connectionInfo.Password = "Welcome1"; 
     SetDBLogonForReport(connectionInfo); 


    } 


    private void SetDBLogonForReport(ConnectionInfo connectionInfo) { 
     TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo; 

     foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos) 
     { 
      tableLogOnInfo.ConnectionInfo = connectionInfo; 
     } 


    } 

}