locked
Sub-Report In Crystal Report For visual Studio 2010 RRS feed

  • Question

  • User-1495932509 posted

    Hello,

    I want to create sub-report but seems to give me error bellow

    Error

    The table 'CustomerView' could not be found. Error in File CrystalReport 4860_4136_{B38B5112-A7EA-4159-A89C-C8F7733B2DE1}.rpt: The table could not be found.

     PLEASE I NEED ASSISTANCE ON THE PROPER WAY TO CREATE SUB-REPORT IN CRYSTAL REPORT

    THANK YOU

    Friday, May 6, 2016 9:18 AM

Answers

  • User-1495932509 posted

    HERE IS MY CODE , I HAVE MANAGE TO GET THIS DONE, I HAVE OE MAIN REPORT AND ONE SUB-REPORT. MY PROBLEM HERE IS , I WANT TO IMPORT SEVERAL SUB-PROCEDURE. BELLOW IS MY CODE PLEASE HELP ME 

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Configuration
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.Web
    Imports CrystalDecisions.ReportSource
    Partial Class Report
    Inherits System.Web.UI.Page

    Private sqlcmd As SqlCommand = New SqlCommand

    Private da As SqlDataAdapter = New SqlDataAdapter

    Private dt As DataTable = New DataTable

    Private dt1 As DataTable = New DataTable


    Private SqlConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("xxx").ConnectionString)


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Genenrate_Report()
    End Sub

    Sub GetData()

    Dim command As SqlCommand = New SqlCommand("CustomerSP", SqlConnection)
    command.CommandType = CommandType.StoredProcedure
    'command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text
    'command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text
    SqlConnection.Open()

    End Sub

    Public Sub Genenrate_Report()

    Try

    Dim command As SqlCommand = New SqlCommand("CustomerSP", SqlConnection)
    command.CommandType = CommandType.StoredProcedure
    'command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text
    'command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text
    SqlConnection.Open()

    Me.da = New SqlDataAdapter(command)
    Me.dt.Clear()
    Me.da.Fill(Me.dt)
    If (Me.dt.Rows.Count > 0) Then
    'Assign data to the primary report
    Dim RptDoc As ReportDocument = New ReportDocument
    RptDoc.Load(Server.MapPath("~/CrystalReport.rpt"))
    RptDoc.SetDataSource(Me.dt)
    SqlConnection.Close()

    Dim command1 As SqlCommand = New SqlCommand("ORderSP", SqlConnection)
    command1.CommandType = CommandType.StoredProcedure
    'command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text
    'command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text
    SqlConnection.Open()

    Me.da = New SqlDataAdapter(command1)
    Me.dt1.Clear()
    Me.da.Fill(Me.dt1)

    SqlConnection.Close()


    'Dim command2 As SqlCommand = New SqlCommand("STOREPORCEDURENAME", SqlConnection)
    'command2.CommandType = CommandType.StoredProcedure
    ''command.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text
    ''command.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text
    'SqlConnection.Open()
    'Dim dt2 As New DataTable
    'Me.da = New SqlDataAdapter(command2)
    'dt2.Clear()
    'Me.da.Fill(dt2)
    'SqlConnection.Close()


    'Get sub report and assign datatable1 to that report
    For Each repOp As ReportObject In RptDoc.ReportDefinition.ReportObjects
    If (repOp.Kind = ReportObjectKind.SubreportObject) Then
    Dim SubRepName As String = CType(repOp, SubreportObject).SubreportName
    Dim subRepDoc As ReportDocument = RptDoc.Subreports(SubRepName)
    subRepDoc.SetDataSource(Me.dt1)
    'subRepDoc.SetDataSource(dt2)
    End If

    Next
    'Assign report to the crystal report viewer
    CrystalReportViewer1.ReportSource = RptDoc
    CrystalReportViewer1.DataBind()
    End If

    Catch ex As Exception
    Response.Write(ex.ToString)
    Finally
    SqlConnection.Close()
    End Try
    End Sub

    End Class

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 7, 2016 4:12 PM