2014-01-23 24 views
0

在搜索互聯網和答案後,我仍然沒有讓我的問題得到解決的位置,我試圖在C#Windows窗體應用程序中使用水晶報告。我在.rpt文件中使用Field Explorer來填充Crystal報表中的數據庫字段。然後使用下面的代碼我在形式上稱爲.rpt文件(以下評論被瀏覽因特網後來添加的。)數據庫登錄窗口中的C#信息,同時顯示水晶報告

 //ReportDocument report = new ReportDocument(); 
     //TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
     //TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 

     // Tables CrTables ; 
     // report.Load("rpt_DailyLog.rpt"); 
     Reports.rpt_GRN report = new Reports.rpt_GRN(); 
     // ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
     //report.Load("rpt_GRN.rpt"); 
     //crConnectionInfo.ServerName = ".\sql2008"; 
     //crConnectionInfo.DatabaseName = "ARM"; 
     //crConnectionInfo.UserID = "sa"; 
     //crConnectionInfo.Password = "test123"; 

     stringcondition = "{GRN.Date}='" + date + "'"; 
     report.RecordSelectionFormula = stringcondition; 

     //CrTables = report.Database.Tables ; 
     //foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) 
     //{ 
     // crtableLogoninfo = CrTable.LogOnInfo; 
     // crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
     // CrTable.ApplyLogOnInfo(crtableLogoninfo); 
     //} 
     //crystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.UserID = "sa" 
     //crystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo.Password = "sapassword" 
     crystalReportViewer1.ReportSource = report; 
     crystalReportViewer1.Refresh(); 

的問題是:當水晶報表加載給的密碼,而其他領域,即我得到的提示服務器名稱,數據庫名稱和用戶名將自動填充,但它僅詢問密碼。我不想要這個提示。請幫助

回答

0

請再次檢查您是否在設計水晶報表時和代碼中同時提供了用戶憑據。您在嚮導中提供的登錄憑據還應與代碼中的登錄憑據相匹配。檢查一次。

+0

如何在報告中提供憑據? – annyyca

0

我不相信密碼可以保存在.rpt文件中,這就是爲什麼在運行時提示您的原因。

您有您需要設置連接信息的代碼(評論):

ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
    crConnectionInfo.ServerName = ".\sql2008"; 
    crConnectionInfo.DatabaseName = "ARM"; 
    crConnectionInfo.UserID = "sa"; 
    crConnectionInfo.Password = "test123"; 
    CrTables = report.Database.Tables ; 
    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) 
    { 
     crtableLogoninfo = CrTable.LogOnInfo; 
     crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
     CrTable.ApplyLogOnInfo(crtableLogoninfo); 
    } 

它看起來像您使用的是自己的功能Reports.rpt_GRN(),你需要實現上述。

+0

我已經註釋掉了這段代碼,因爲即使我沒有註釋掉我的代碼,它仍然沒有解決我的問題,它再次要求我輸入密碼。 – annyyca

+0

另外Reports.rpt_GRN不是任何功能,而「報告」是「rpt_GRN.rpt」所在的文件夾。爲了使這個報告的對象我做到了。 – annyyca