This is a migrated thread and some comments may be shown as answers.

Subreport refuses to work

3 Answers 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alex Tushinsky
Top achievements
Rank 2
Alex Tushinsky asked on 20 Sep 2010, 09:52 PM
I've now spent a full day simply trying to get some data to my subreport.  I'm using the following code, which seems to do absolutely nothing.  What am I doing wrong??

Public Sub New()
    InitializeComponent()
End Sub
Private Sub admin_invoice_details_ownitnow_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
    Dim SQL As New StringBuilder
 
    SQL.AppendLine("       SELECT  ISNULL(products.itemid, 0) AS lotid,")
    SQL.AppendLine("                invdesc.itemdesc,")
    SQL.AppendLine("                invdesc.amount")
    SQL.AppendLine("        FROM    invdesc")
    SQL.AppendLine("                INNER JOIN products ON products.ProductID = invdesc.itemid")
    SQL.AppendLine("        WHERE   invdesc.invoiceid = @invoiceid")
 
    Dim sqlDataSource1 As New SqlDataSource()
    sqlDataSource1.ConnectionString = HttpContext.Current.Session("Conn")
    sqlDataSource1.SelectCommand = SQL.ToString
    sqlDataSource1.Parameters.Add("@invoiceid", DbType.Int32, "=Parameters.invoiceid")
    Me.DataSource = sqlDataSource1
End Sub

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 21 Sep 2010, 02:16 PM
Hi Alex Tushinsky,

As noted in the Using the NeedDataSource event to connect data help article, you should make sure that:
  • the report has no datasource set, otherwise the NeedDataSource event would not fire.
  • when you're in the context of the NeedDataSource event, you should set the DataSource to the processing report object and not the definition i.e.

    Private Sub Report1_NeedDataSource(ByVal  sender As Object, ByVal e As System.EventArgs)
         ......
        TryCast(sender, Telerik.Reporting.Processing.Report).DataSource = sqlDataSource1
    End Sub

All the best,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex Tushinsky
Top achievements
Rank 2
answered on 21 Sep 2010, 04:25 PM
That did not solve my problem.  Perhaps a different approach? This is all quite frustrating.  There aren't any clear examples of how to do this anywhere on the Telerik site or help info.  

Basically I am running these reports from several websites.  The connection strings for each site is different, although the schema of the databases is the same.  My reports are in a separate project, with the DLL in the Bin folder of each web site (no additional configuration for reports, no app.config file).  For every report that I run, I specify a query in the following routines  (btnPrint_Click brings up the panel with the report viewer, sets the session vars that are used by the subreport, then sets up the report and gets the main report's data - GetData() routine.  The code in my previous post is in the subreport itself.):

Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
      pnlInvoice.Visible = False
      pnlPrint.Visible = True
      Session("Conn") = GetConn("LocalSQLServer")
 
      Dim MyRep As CreateAuctionReporting.admin_invoice_report_ownitnow
       MyRep = New CreateAuctionReporting.admin_invoice_report_ownitnow
       MyRep.DataSource = GetData()
       ReportViewer1.Report = MyRep
   End Sub
 
  Function GetData() As DataSet
      Dim InvoiceID As Long = 0
      Try
          InvoiceID = eRequest(Request("p"), "invoiceid")
      Catch ex As Exception
          InvoiceID = 0
      End Try
      HttpContext.Current.Session("invoiceid") = InvoiceID
      Dim DS As New DataSet
       Dim SQLConn As SqlConnection = DoConn("LocalSQLServer")
      Dim myCommand As New SqlCommand("admin_buyer_invoice_single", SQLConn)
      myCommand.CommandTimeout = 3600
      myCommand.CommandType = CommandType.StoredProcedure
      myCommand.Parameters.Add("@invoiceid", SqlDbType.Int).Value = InvoiceID
 
      Dim myData As New SqlDataAdapter(myCommand)
      myData.Fill(DS)
 
      myCommand.Dispose()
      UndoConn(SQLConn)
 
      Return DS
  End Function
0
Steve
Telerik team
answered on 24 Sep 2010, 10:07 AM
Hello Alex,

It is not immediately clear from your posts whether you're after a master-detail scenario - if so please review the following article: Creating Master-Detail Reports Using SubReports. If this is not the case and the subreport is used simply as a separate Data Item, then both approaches of binding from the calling application and from the NeedDataSource event are valid (note again that the NeedDataSource event would not be fired if you have DataSource set).
In your original post you can alter the code in the event like this:

Private Sub admin_invoice_details_ownitnow_NeedDataSource(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.NeedDataSource
 
 Dim report As Telerik.Reporting.Processing.Report = DirectCast(sender, Telerik.Reporting.Processing.Report)
    Dim SQL As New StringBuilder
  
    SQL.AppendLine("       SELECT  ISNULL(products.itemid, 0) AS lotid,")
    SQL.AppendLine("                invdesc.itemdesc,")
    SQL.AppendLine("                invdesc.amount")
    SQL.AppendLine("        FROM    invdesc")
    SQL.AppendLine("                INNER JOIN products ON products.ProductID = invdesc.itemid")
    SQL.AppendLine("        WHERE   invdesc.invoiceid = @invoiceid")
  
    Dim sqlDataSource1 As New SqlDataSource()
    sqlDataSource1.ConnectionString = HttpContext.Current.Session("Conn")
    sqlDataSource1.SelectCommand = SQL.ToString
    sqlDataSource1.Parameters.Add("@invoiceid", DbType.Int32, report.Parameters("invoiceid").Value)
    Me.DataSource = sqlDataSource1
End Sub


Kind regards,
Steve
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Alex Tushinsky
Top achievements
Rank 2
Answers by
Steve
Telerik team
Alex Tushinsky
Top achievements
Rank 2
Share this question
or