[英]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.