locked
Crystal Report Viewer - xsd file - subreport - mdf in App_Data RRS feed

  • Question

  • User1324324531 posted

    Have designed a Crystal Report and based off xsd dataset. Two datatables in the xsd file.

    Database mdf is in App_Data folder.

    I have one report Test10a.rpt that includes Test10b.rpt as subreport with linked id field that exists on both reports.

    Here is code so far.  I don't know how to get the subreport to fill with data.  

    Getting error on line to set datasource to table from xsd file for the subreport.

    Object reference not set to an instance of an object.

    Any help would be appreciated.

    <%@ Page Language="VB" %>
    <%@ Import Namespace="CrystalDecisions.CrystalReports.Engine" %>
    <%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim dsReport As New Report1()
    Dim connectionString As String = WebConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ConnectionString
    Dim con As New SqlConnection(connectionString)
    Dim strSelect As String = "SELECT AbstractId, AbstractTitle, AbstractDesc, LearningObjective1, LearningObjective2, LearningObjective3, Objectives, Methodology, Results FROM tblAbstracts"
    Dim cmd As New SqlCommand(strSelect, con)
    Dim dAdapter As New SqlDataAdapter(cmd)
    con.Open()
    dAdapter.Fill(dsReport.Tables("Abstracts"))
    strSelect = "SELECT aspnet_UserMoreInfo.Firstname, aspnet_UserMoreInfo.Lastname, tblAbstractUserLink.AbstractId FROM aspnet_UserMoreInfo INNER JOIN tblAbstractUserLink ON aspnet_UserMoreInfo.UserId = tblAbstractUserLink.UserId"
    Dim cmd2 As New SqlCommand(strSelect, con)
    Dim dAdapter2 As New SqlDataAdapter(cmd2)
    Dim dsReport1 As New Report1()
    dAdapter2.Fill(dsReport1.Tables("Presenters"))
    con.Close()
    Dim crystalReport As New ReportDocument()
    crystalReport.Load(Server.MapPath("Test10a.rpt"))
    crystalReport.Subreports.Item("Test10b.rpt").SetDataSource(dsReport1.Tables("Presenters"))
    crystalReport.SetDataSource(dsReport)
    CrystalReportViewer1.ReportSource = crystalReport


    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
    AutoDataBind="True" EnableDatabaseLogonPrompt="False"
    EnableParameterPrompt="False" Height="1039px"
    ReportSourceID="CrystalReportSource1"
    Width="901px" />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
    <Report FileName="Test10a.rpt">
    </Report>
    </CR:CrystalReportSource>
    </div>
    </form>
    </body>
    </html>

    How do I get the subreport to show data for each record of the main report?

    Thank you for any help with this?

    Thursday, May 3, 2012 4:43 PM

Answers

  • User1324324531 posted

    I found my error.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 4, 2012 4:53 PM