繁体   English   中英

Crystal Reports-更改表位置无效

[英]Crystal Reports - Changing Table Locations No working

我有一个用VB6开发的应用程序,正在迁移到.Net Framework 4.0。 有一个报告可以在原始应用程序中正常运行,但是迁移的应用程序不能在原始应用程序上运行。 作为一项特殊功能,此报告在运行时在两个表中更改了属性“位置”(实际上是可以看到的),该两个表用于生成用于馈送该报告的SQL,但是在“射击”时,请重新调整属性为“位置”没有反映出来,可以使用“ SQL Server Profiler”工具显示:

objReportDocument.Database.Tables(0).Location = "NameReferenceTable""

我的意思是:构建报表时,他们使用了数据库的5个数据库表:Table1,Table2,Table3,Table4和Table5。 后来,在数据库中,表Table1和Table2被删除。 这个想法是,在运行时,存储过程像临时表一样构造了Table1和Table2,其原始名称更多为任何id字符串; 报表上升时必须使用此新数据库表。

当您遍历报表的Tables数组(ReportDocument.DataBase.Tables(n))时,对于每个表,您都可以看到两个关键属性:名称和位置。 我理解,位置属性向Crystal Reports指示应该使用哪些表来构建重排,这是真的吗?

我没有使用Crystal Reports的丰富经验,我调查了两个星期为什么未生成此错误的原因……希望您能对我有所帮助,我非常感谢。

问候,

法比安。

我将提供一种用于我的应用程序中的Crystal Reports对象的方法。 这仅用于设置报告的登录信息(我们的报告使用内置的安全性),但是如果我正确理解了您的问题,那么您应该也可以添加/修改此方法来设置Location

以下方法中使用的属性是:

Me.ConnectionInfo的类型为CrystalDecisions.Shared.ConnectionInfo

Me.LogOnInfo的类型为CrystalDecisions.Shared.TableLogOnInfo

Me.Report类型为CrystalDecisions.CrystalReports.Engine.ReportDocument

另外, g_strDbg_strServerg_strMirror是一些String ,它们的值无关。

我发现在.NET中使用Crystal Reports的一件事是,您需要在Table级别设置属性,如下面的方法所示。 希望这可以帮助您解决问题。

''' <summary>
''' Apply the database connection info to all tables recursively.
''' </summary>
''' <param name="crxRpt">The report document (or subreport) to apply connection info.</param>
Private Sub SetConnectionInfo(ByVal crxRpt As ReportDocument)
    Dim reportObject As ReportObject
    Dim subReportObject As SubreportObject
    Dim section As Section
    Dim t As Table

    For Each t In crxRpt.Database.Tables
        ' if the DatabaseName in the report is <special db name>,
        ' we need to make sure to set the DatabaseName to the environment
        ' that the user is currently connected to in order to be able to
        ' pull the correct information for the report
        If t.LogOnInfo.ConnectionInfo.DatabaseName = "<special db name>" Then
            Me.ConnectionInfo.DatabaseName = g_strDb
        Else
            Me.ConnectionInfo.DatabaseName = t.LogOnInfo.ConnectionInfo.DatabaseName
        End If

        ' only ApplyLogOnInfo for tables that are being pulled from the SQL
        ' server, this avoids problems that arise with reports that are
        ' created using field definition files
        If t.LogOnInfo.ConnectionInfo.ServerName = g_strServer OrElse t.LogOnInfo.ConnectionInfo.ServerName = g_strMirror Then
            t.ApplyLogOnInfo(Me.LogOnInfo)
        End If
    Next t

    For Each section In crxRpt.ReportDefinition.Sections
        For Each reportObject In section.ReportObjects
            If reportObject.Kind = ReportObjectKind.SubreportObject Then
                subReportObject = CType(reportObject, CrystalDecisions.CrystalReports.Engine.SubreportObject)
                SetConnectionInfo(subReportObject.OpenSubreport(subReportObject.SubreportName))
            End If
        Next reportObject
    Next section
End Sub

从设置方法中调用上述方法:

''' <summary>
''' Initialize the database connection info.
''' </summary>
Public Sub SetUpReport()
    Me.LogOnInfo = New TableLogOnInfo

    Me.ConnectionInfo.UserID = conUID
    Me.ConnectionInfo.Password = conPWD
    Me.ConnectionInfo.ServerName = g_strServer
    Me.ConnectionInfo.DatabaseName = g_strDb

    Me.SetConnectionInfo(Me.Report)
End Sub

每当我们需要显示/打印报告时,就会调用SetUpReport()

好吧,终于找到解决方案了...

  1. 在我使用ODBC的BD区域中,该区域的关联用户no在BD中具有模式关联,然后在存储过程创建了临时表时,在shchema bdo下创建了该表,但是当Crystal报表增加了报表时(与关联用户的ODBC)找不到临时表。 因此,我将一个模式与ODBC中使用的用户相关联。

  2. 我的原始报告很旧,所以我不得不在VS2012中打开每个报告,覆盖报告以更新格式并在Main Report Preview中进行测试。

暂无
暂无

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

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