0

在默认安装 Crystal Reports 的情况下使用 Visual Studio 2005。

当我创建一个报表时,Crystal 要求提供数据库,然后我将我的开发数据库提供给它。在应用程序中,我创建了一个 DataTable 并将其传递给报告,然后将其传递给 CR 查看器。在运行时,报表对象和查看器都不需要查看数据库,因为我已经检索了表。

当应用程序交给用户时,一切正常。他们看不到开发数据库。

有一次,在生产办公室,我在生产现场创建了一个报表,我没有通过指定开发数据库来创建水晶报表,而是给它生产数据库。回到我自己的办公室,在 VS 中运行,报告尝试连接到开发数据库,​​但失败了。(它不可见。)

所以,他们看不到我的开发数据库不是问题,但我看不到生产数据库是一个问题。

问题是:出现这种情况是因为在 VS 中运行与运行已安装的应用程序不同吗?为什么报告仍然尝试连接到数据库?我该如何控制它?

4

3 回答 3

1

When you create the report you should be able to do report.SetDataSouce(DataSet) and pass it your dataset that contains the tables that the report uses.

于 2009-06-17T17:48:16.357 回答
1

我觉得我跟...

当您在 VS 中查看 .rpt 时,右键单击字段资源管理器窗口中的数据库字段,然后转到“设置数据源位置”。它对您的连接有何影响?它是否指向生产数据库服务器?此设置将存储在 .rpt 文件中,因此这可能会解释您的问题。

于 2008-12-16T20:20:12.300 回答
0

问题是:出现这种情况是因为在 VS 中运行与运行已安装的应用程序不同吗?为什么报告仍然尝试连接到数据库?我该如何控制它?

您可以根据您的报告内容进行控制

如果您的报告包含一个表格,并且您使用 DataTable 将此表格传递给您的报告,则报告将正常工作

但是当您的数据表未提供所有报告数据时,通常当您的报告包含 2 个或更多表时,报告会尝试连接到原始数据库位置

在这种情况下,您需要传递 DATASET 以报告包含所有表

这里我的代码使用 2 个表格表单作者和标题作者

'Build a SQL statement to query for the authors table 

Dim sqlString As String = "SELECT * FROM authors"

'Retrieve the data using the SQL statement 

adoOleDbDataAdapter = New OleDbDataAdapter(sqlString, adoOleDbConnection)

'Build a SQL statement to query for the titleauthor table 

sqlString = "SELECT * FROM titleauthor" 

'Retrieve the data using the SQL statement 

adoOleDbDataAdapter2 = New OleDbDataAdapter(sqlString, adoOleDbConnection) 

'Create a instance of a Dataset 

DataSet1 = New DataSet() 

'Fill the dataset with the data with author information 

adoOleDbDataAdapter.Fill(DataSet1, "authors") 

'Fill the dataset with the data with titleauthor information. 
'The table name used in the Fill method must be identical to the name 
'of the table in the report. 

adoOleDbDataAdapter2.Fill(DataSet1, "titleauthor") 

'Pass the dataset to the report 

crReportDocument.Database.Tables(0).SetDataSource(DataSet1) 

'View the report 

CrystalReportViewer1.ReportSource = crReportDocument
于 2014-05-14T08:02:46.710 回答