链接的子报表中缺少数据

时间:2019-06-18 22:42:45

标签: vb.net crystal-reports subreport

我正在vb.net中为Visual Studio 2016开发。我正在使用从SAP下载的最新VS水晶报表。我正在使用带有可视foxpro表的Advantage Database服务器-报表的每个源表都是VFP可用表,而所构建的实际报表表也是如此。 我有一个主报告和一个子报告,作为子报告嵌入在主报告的详细信息部分。我有一个主表将数据馈入主报表,一个明细表将数据馈入子报表。两个表共享一个相同的索引字段,该字段用于主报表和子报表之间的链接。详细信息字段显示在子报表的“详细信息”部分中,摘要字段显示在子报表的页脚部分中。运行报表时,仅显示明细表的两个字段(7个字段中的oline和custid),并且仅显示明细表的第一行。我需要显示所有详细信息字段,并需要显示详细信息表的所有行以显示主报告中的当前客户。

我已经验证了链接设置,已经验证了两个表在每一行的每个字段中都有数据,并且链接数据在两个表中均有效。我已在子报表的“详细信息”部分中包含了链接字段(“ custid”),以验证子报表是否从主报表中获取了正确的链接数据(这是在子报表的“详细信息”部分中显示的字段之一)并且该字段在每个页面上显示了该页面上主要数据的正确链接数据。主报告正文可正确打印所有主要记录。子报表没有参数(链接的自动定义参数除外)并且没有公式,每个报表只有一个数据源表,并且子报表直接在详细信息部分显示字段。

' Create the reporting tables
lcSQL = "CREATE Table " & lcTempDName & " (CustID Char(5), CustName 
    char(9), Address char(25), Dept char(3)) as free table"

If System.IO.File.Exists(lcTempDName & ".dbf") Then
     System.IO.File.Delete(lcTempDName & ".dbf")
End If
If System.IO.File.Exists(lcTempDName & ".cdx") Then
    System.IO.File.Delete(lcTempDName & ".cdx")
End If

loSQL.Connection = loTempConn
loSQL.CommandText = lcSQL
Try
    loSQL.ExecuteNonQuery()
    lcSQL = "Create Index CustID on " & lcTempDName & "(CustID)"
    loSQL.CommandText = lcSQL
    Try
        loSQL.ExecuteNonQuery()
    Catch ex As Exception
         MessageBox.Show("Error creating index on temporary Reporting 
             table.", "")
    End Try
Catch ex As Exception
     MessageBox.Show("Error creating temporary Reporting table.", "")
End Try

lcSQL = "CREATE Table " & lcTempDSubName & " (CustID Char(5), oline 
    char(3), odate date, otype char(15), oqty Numeric(8, 2), " &
    "oamount Numeric(8, 2), ojob char(6)) as free table"

If System.IO.File.Exists(lcTempDSubName & ".dbf") Then
    System.IO.File.Delete(lcTempDSubName & ".dbf")
End If
If System.IO.File.Exists(lcTempDSubName & ".cdx") Then
    System.IO.File.Delete(lcTempDSubName & ".cdx")
End If

loSQL.Connection = loTempConn
loSQL.CommandText = lcSQL
Try
    loSQL.ExecuteNonQuery()
    lcSQL = "Create Index CustID on " & lcTempDSubName & "(CustID)"
    loSQL.CommandText = lcSQL
    Try
        loSQL.ExecuteNonQuery()
    Catch ex As Exception
        MessageBox.Show("Error creating index on temporary Reporting 
            subtable", "")
    End Try
Catch ex As Exception
    MessageBox.Show("Error creating temporary Reporting subtable.", "")
End Try
  .
  .
' Populate the report tables
' I have opened the main source VFP table as loCustTable
for each loCustRow in loCustTable.rows
    lcSQL = "INSERT into " & lcTempDName & " (CustID, CustName, Address, 
        Dept) values ('" & loCustRow("custid") & "', '" & 
        loCustRow("custname") & "', '" & loCustRow("address") & "', '" & 
        loCustRow("dept") & "')"
    loSQL.Connection = loTempConn
    loSQL.CommandText = lcSQL
    Try
        loSQL.ExecuteNonQuery()
    Catch ex As Exception
        MessageBox.Show("Error creating temporary Reporting subtable.", 
            "")
    End Try
      .
      .
    ' I have opened the source detail VFP table as loDetailTable 
    for each loDetailRow in loDetailTable.rows
        lcSQL = "INSERT into " & lcTempDSubName & " (CustID, oline, 
            odate, otype, oqty, oamount, ojob) values ('" & 
            loDetailRow("custid") & "', '" &  loDetailRow("oline") &  "', 
            '" & loDetailRow("odate") & "', '" & loDetailRow("otype") & 
            "', " & loDetailRow("oqty") & ", " & loDetailRow("oamount") & 
            ", '" & loDetailRow("ojob") & "')"
        loSQL.Connection = loTempConn
        loSQL.CommandText = lcSQL
        Try
            loSQL.ExecuteNonQuery()
        Catch ex As Exception
            MessageBox.Show("Error creating temporary Reporting 
                subtable.", "")
        End Try
    next
next

' I now have created a main report table holding one record for each cust 
  and a subreport table holding multiple records for each cust found in 
  the main table - These tables are verified after construction to be 
  correct (using VFP to open the tables directly for viewing - not left 
  open for the actual report run)

' I now select the records from the two tables
lcSQL = "SELECT * from " & lcTempDName
loAdapter.SelectCommand = loSQL
loAdapter.SelectCommand.Connection = loTempConn
loAdapter.SelectCommand.CommandText = lcSQL
Try
    loAdapter.Fill(loReportSet)
    loReportTable = loReportSet.Tables(0)
Catch ex As Exception
    MessageBox.Show("Error opening report table", "")
End Try

lcSQL = "SELECT * from " & lcTempDSubName
loAdapter.SelectCommand = loSQL
loAdapter.SelectCommand.Connection = loTempConn
loAdapter.SelectCommand.CommandText = lcSQL
Try
    loAdapter.Fill(loReportSet)
    loSubTbl = loReportSet.Tables(0)
Catch ex As Exception
    MessageBox.Show("Error opening subreport table", "")
End Try
' The report tables are also verified accurate from within vb.net prior to 
  running the report itself
   .
   .
' now generate the report
' The reports are built with fields from the report tables
Dim pS As New System.Drawing.Printing.PageSettings
pS.Landscape = False
' get printer data
Dim pDialog As New PrintDialog
gcPrintDialog = pDialog.ShowDialog
If gcPrintDialog = DialogResult.OK Then
    gcPrinterName = pDialog.PrinterSettings.PrinterName
    goPrinterSettings = pDialog.PrinterSettings
End If

dim oReport As New ReportDocument
dim rptname as String = "mainreport.rpt"
oReport.Load(rptName)
oReport.SetDataSource(loReportTable)                    
oReport.Subreports(0).SetDataSource(loSubReportTable)
' NOTE I have tried:
     oReport.Subreports("subreport.rpt").SetDataSource(loSubReportTable)
  with no difference in results
oReport.PrintToPrinter(goPrinterSettings, pS, False)

如前所述-该报告将按预期的方式为每个客户打印一页,但是嵌入的子报表仅打印部分第一行详细信息(某些但不是全部字段),并且仅打印第一行详细信息,无论如何该客户的子报表中有许多实际记录。打印的第一行始终与预期的主报告CustID相匹配。子报表中的每个字段都直接从子报表中选择为字段,没有公式,也没有参数。没有任何字段或任何节的禁止选择。没有错误消息。

0 个答案:

没有答案