[英]crystal report database login prompt when using c# and ms-access and dataset
[英]How to connect Crystal Report to MS Access database using C# in Windows Form Application
我想在Windows窗體應用程序中使用C#將Crystal Reports連接到MS Access數據庫。
我正在使用下面的代碼將Crystal Report與MS Access數據庫連接,但是它不起作用。
ReportDocument crReport = new ReportDocument();
string sTemplatePath = "D:\\Report\\Sample.rpt";
crReport.Load(sTemplatePath);
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo tConnInfo = new ConnectionInfo();
tConnInfo.DatabaseName = "D:\\AccessDB\\AccessDb.mdb";
tConnInfo.Password = "abcd";
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crReport.Database.Tables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = tConnInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
誰能幫助我完成這項任務? 我會非常感謝你。
您需要采取的步驟:
最后添加以下代碼:
//Assign data source details to the report viewer if (this.crystalReportViewer1.LogOnInfo != null) { TableLogOnInfos tlInfo = this.crystalReportViewer1.LogOnInfo; foreach (TableLogOnInfo tbloginfo in tlInfo) { tbloginfo.ConnectionInfo = tConnInfo; } } crystalReportViewer1.ReportSource = crReport;
一旦您掌握了基礎知識,就可以使用所見即所得的設計器開始研究報告的設計!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.