简体   繁体   English

如何使水晶报表的 Access 数据库数据源路径动态化?

[英]How to make Access Database data source path dynamic for Crystal Report?

I have developed a Windows Form App using C# & Microsoft Access Database (.accdb) .我使用C#Microsoft Access Database (.accdb)开发了一个 Windows 表单应用程序。 I have created a Crystal Report.我创建了一个水晶报表。 In Crystal Report there is an option called "Database Expert" .在 Crystal Report 中有一个名为“Database Expert”的选项。 Using "Database Expert" option I have attached my Access database file with Crystal Report using OLE DB (ADO) like below picture:使用“数据库专家”选项,我使用OLE DB (ADO)将我的 Access 数据库文件与 Crystal Report 附加在一起,如下图所示:

数据源

Now I have created another form and bind a Crystal Report Viewer with this form.现在我创建了另一个表单并将 Crystal Report Viewer 与该表单绑定。 I have coded these code on Form Load Event:我在表单加载事件中编写了这些代码:

private void BillingInvoiceForm_Load(object sender, EventArgs e)
{
    int BillPrint = Billing_Form.BillNoToPrint;
    ReportDocument crypt = new ReportDocument();
    crypt.Load(@"Report\BillingReport.rpt");
    crypt.RecordSelectionFormula = "{Bill_Master.Bill_No} =  " + BillPrint + "";
    crystalReportViewer1.ReportSource = crypt;
    crystalReportViewer1.Show();
}

As you can see there is a path like "F:\Visual Studio Projects\BillingSystem\db\My_Database.accdb"如您所见,有一个类似“F:\Visual Studio Projects\BillingSystem\db\My_Database.accdb”的路径

When I run this app into my machine, everything works fine but when I deploy this app into another machine it gets stuck.当我在我的机器上运行这个应用程序时,一切正常,但是当我将这个应用程序部署到另一台机器上时,它就卡住了。 Because app can not find path like "F:\Visual Studio Projects\BillingSystem\db\My_Database.accdb".因为应用程序找不到像“F:\Visual Studio Projects\BillingSystem\db\My_Database.accdb”这样的路径。

So my question is that how can I make Crystal Report data source path dynamic so that this app can be run on every computer.所以我的问题是,如何使 Crystal Report 数据源路径动态化,以便该应用程序可以在每台计算机上运行。

Best option is to switch to ODBC as the data source.最好的选择是切换到 ODBC 作为数据源。 That way, the same ODBC DSN on different machines can point at different physical locations.这样,不同机器上的同一个 ODBC DSN 可以指向不同的物理位置。

It is possible to change the data source in code but that requires more advanced knowledge of the Crystal runtime and comes with other challenges as well.可以在代码中更改数据源,但这需要更高级的 Crystal 运行时知识,并且还会带来其他挑战。 There are 3rd-party Crystal Reports viewers that handle that challenge but I would advise you to go with the simpler solution of using ODBC.有第 3 方 Crystal Reports 查看器可以处理该挑战,但我建议您使用 go 使用 ODBC 的更简单解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM