[英]How to connect Crystal Report to MS Access database using C# in Windows Form Application
I want to connect Crystal Reports to MS Access database using C# in my windows form application. 我想在Windows窗体应用程序中使用C#将Crystal Reports连接到MS Access数据库。
I am using below code to connect crystal report with MS Access database but it is not working. 我正在使用下面的代码将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);
}
Can anyone help me to achieve this task? 谁能帮助我完成这项任务? I will be very thankful to you.
我会非常感谢你。
Steps you need to take: 您需要采取的步骤:
Finally add the following code: 最后添加以下代码:
//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;
Once you have got the basics working, you can start playing around with the design of your report, using the WYSIWYG designer! 一旦您掌握了基础知识,就可以使用所见即所得的设计器开始研究报告的设计!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.